Remove element from Array

What if you want to delete an element from Array ??

Mostly people use delete command  but it leaves undefined behind it

>>> var list = [1,2,3];

>>> delete list[1];

>>> list

[1, undefined, 3]

Now try splice instead of delete

>>> var list = [1,2,3];
>>> list.splice(1, 1); // Remove one element, returns the removed ones.
[5]
>>> list[4, 6]
And it's done... 

Leave a Reply

Your email address will not be published. Required fields are marked *