Snippets → jQuery Code Snippets → Remove Specific Value from Array Remove Specific Value from Array Chris Coyier on Jan 29, 2012 var arr = [1, 2, 3, 4, 5]; var removeItem = 2; arr = $.grep(arr, function(value) { return value != removeItem; });
Missing semicolon on the first line, other than that, cool beans
Why not use native functions?
var arr = [1, 2, 3, 4, 5];
var removeItem = 2;
arr.splice(arr.indexOf(removeItem ), 1);
THANK YOU so much
Can plz u add a live example of js.fiddle link.
Here you go:
http://codepen.io/chriscoyier/pen/65/3
Exist Splice() method, the method it remove item from the index in the array.
code:
var arr = [1, 2, 3, 4, 5];
var removindexitem = 2;
arr.splice(removindexitem );
Reff:
http://www.w3schools.com/jsref/jsref_splice.asp
You would need to know the index of the value in the array for this to work. This is not always guaranteed, plus also native indexOf does not work on versions of IE below IE9.
array.pull(value); //remove
array.push(value); //add
sorry…
array.pop(value) // remove
@oottoo
array.pop(value) removes only last value from array.
pop functionality is used only for last element .