Firstly find the index of the element you want to remove:
1 2 | var array = [2, 5, 9]; var index = array.indexOf(5); |
Note: browser support for indexOf is limited, it is not supported in IE7-8.
Then remove element using its index and function 'splice':
1 2 3 | if (index > -1) { array.splice(index, 1); } |
The second parameter of splice is the number of elements to remove.
Note: splice modifies the array in place and returns a new array containing the elements that have been removed.
