-1
I need to remove from the array
the current object being processed:
arrai = [{parent:1,dialog_node:2}, {parent:1,dialog_node:3}, {parent:1,dialog_node:4}, {parent:9,dialog_node:1}, {parent:9,dialog_node:6}];
tree = {parent:1,dialog_node:2};
arrai.forEach(function(value){
if(tree.parent == value.parent){
node.parent = value.parent;
node.children.push(value.dialog_node);
_.reject(arrai, function(el) {
return el.dialog_node === tree.dialog_node; });
}
});
I would like to end the elements that fit into the if
are out of the array
.
if you have the example of this array?
– novic
remove an item from the array in which the
forEach
is running is not a good idea, better add a reference to everything you want to remove in another array, and after theforEach
rule out everything– Ricardo Pontual
Adjusted @Virgilionovic
– ALE_ROM