Bug(?) in RemoveNodeData function

I think there is a bug in the RemoveNodeData function…

I’ll try to do this:
-Parse nodeDataArray
-Delete all nodes with key != 0 (there is only a node with this key)
But i need to cicle two times the node array because on the first cicle the last node (not with key == 0) isn’t deleted.

This is the code:

deleteObj is a function indipentent of deleting node from model. It has this anomalous behaviour also without deleteObj.

Thanks :)

This is not a bug in GoJS, but a bug in your code.

Model.removeNodeData modifies the Model.nodeDataArray.

So your iteration through the Array is modifying the Array while you are iterating. You should not do that – copy the Array first and call forEach on the copied Array, or gather the elements to be deleted for deletion after forEach is done, or iterate without using forEach.

Oh… wow.
You right… I’m dumb ^^" I’ve not considering forEach particular beahviour…

For anyone that have same problem:
the easiest solution is parse node array with a “backward for”, so starting from last node and cicle until the first node.

for(let i = model.NodeDataArray.length; i > 0; i–){

This because the method removeNodeData re-arrange the array dimansion, so, cicling it from the end the problem is solved :)

Ty @walter