You can use the indexOf method like this:
indexOf
var index = array.indexOf(item); if (index !== -1) { array.splice(index, 1); }
Note: You'll need to shim it for IE8 and below
var array = [1,2,3,4] var item = 3 var index = array.indexOf(item); array.splice(index, 1); console.log(array)
2.1m questions
2.1m answers
60 comments
57.0k users