if (mappedArr.hasOwnProperty(_id)) {\r
mappedElem = mappedArr[_id];\r
// If the element is not at the root level, add it to its parent array of children.\r
- if (mappedElem.parentGroupId) {\r
+ if (mappedElem.parentGroupId && mappedArr[mappedElem['parentGroupId']]) {\r
mappedArr[mappedElem['parentGroupId']]['children'].push(mappedElem);\r
}\r
// If the element is at the root level, add it to first level elements array.\r