You need to find the index of the node child in the array of parent elements. It should be as simple as looping over an array of parent elements until you hit the child id.
Once you have the index of the node child, use it as the first parameter in the splice function
See the example below (you need to add error checking code, etc. for situations where the parent or child is not found)
function getParent(r, a) { return a.id === child.parentActivityId ? a : a.items.reduce(getParent, r); } var node = data.reduce(getParent, {}); var theChildIndex = 0; for (i = 0; i < node.items.length; i++) { if (node.items[i].id == child.id) { theChildIndex = i; break; } } node.items.splice(theChildIndex,1);
Nogusta
source share