Remove an element in a JavaScript Array

If you know the index of the element to remove, you could use the splice method, like this:

var a=['one','two','three','four'];
a.splice(1,1); // Removes 1 element from index 1
alert(a); // Results in 'one','three','four'

If you don’t know the index, but the value of the element, you could add a little method to the Array class like this: