In Javascript, I have an array of objects like so:
var array = [{ foo: 'bar' }, { foo: 'baz' }, { foo: 'qux' }];
which looks like this, really...
[0: {...}, 1: {...}, 2: {...}]
and I delete the second one:
delete array[1];
then I have this:
[0: {...}, 2: {...}]
How can I adjust this array so the keys are back in numerical order?
I believe Array.splice is what you are looking for in this case
array.splice(1,1);
Use the splice method instead:
array.splice(1, 1);
Will remove 1 object at index 1, without leaving an empty space.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With