0

(Turned out it was a combined thing: a lazy console, and my old code where I started using arrays in function calls instead of a single number and thus handing over references that lead to modification of the actual and original array.)

I have problems with an array, that should have the value:

[0,1,2]

Now the problems. To start with the most obviously curious event, in a loop the two consecutively running lines:

anr = numberarray[i];
console.log('delete',anr,numberarray);

show

"delete" 2 Array [ -1, 1, 2 ] 
"delete" 1 Array [ -1, 1, 2 ] 
"delete" 0 Array [ -1, 1, 2 ]

Later on in the code the array is changed. (Actually the first number in the array was changed to -1.)

(Deleted part of my original text, as it's irrelevant for the actual question.)

Community
  • 1
  • 1
John
  • 605
  • 9
  • 28
  • 1
    My guess: [console.log is lazy about evaluating arrays](http://stackoverflow.com/q/4057440/1048572). But without showing us your `.deleteFromObjectList` method, we can hardly help. – Bergi May 06 '15 at 05:38

1 Answers1

1

Not sure if this is the cause of your problem but, when you loop through an array an internal counter is made. So when you delete items from the same array as the array you are looping "strange" things happen.

So make a copy of the array and loop through this array and delete the items in the original array.

Hope this makes sense.