Remove Specific Value from Array
var arr = [1, 2, 3, 4, 5];
var removeItem = 2;
arr = $.grep(arr, function(value) {
return value != removeItem;
});
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);
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.