Delete From Javascript array reorder

116 Views Asked by At

I am deleting from a javascript array. After the delete the array gets reordered.

Array [ Object, Object, Object, Object, Object, Object ];
    0 Object
       d:17065
    1 Object
       d:17156
    2 Object
       d:17246
    3 Object
       d:17065
    4 Object
       d:17156
    5 Object
       d:17338
for(d = 0; d < delete_array.length; d++)
{
    data_array[0].splice(delete_array[d],1);
}

After the above deletion. The array changes to.

Array [ Object, Object, Object ];
0 Object
   d:17156
1 Object
   d:17065
2 Object
   d:17246
3 Object

How do I prevent this from happening?

1

There are 1 best solutions below

0
On

Kind of messy. But when I would delete an array object, then the order would change. So if i delete position 0, then next loop all of the other objects have now shifted. So i was getting the incorrect outcome. By grabbing the indexof each loop. I am delete exactly what I want. https://repl.it/K9sr/3