Reputation: 1
a = ['a','b','c','d','e'];
console.log(a.splice(1));
console.log(a);
In splice documentation, it says that skipping the delete parameter will delete all array items, yet here they're not; the first one is left out. Why is this?
Edit: My expectations was that haveing the omission of the delete parameter would cause to delete all the items of the array. But now after read Baconnier comment I understand that removes all after the index (first parameter).
then all the elements from start to the end of the array will be deleted. start being 1 in your case.
Upvotes: 0
Views: 67
Reputation: 160
a = ['a','b','c','d','e'];
console.log(a.splice(0));
console.log(a);
Arrays start at 0, if you want to delete all elements including the first one you need to pass 0 as the first parameter.
Upvotes: 1