JQuery to remove array element by value

by Subramanian 2014-02-13 10:47:17

JQuery - remove array element by value :

Method -1 :

var arr = [Subhu,Mohan,Kannan,Sathish,Hari];
var removeItem = "Kannan";

newArray = jQuery.grep(arr, function(value) {
return value != removeItem;
});

Result:

[Subhu,Mohan,Sathish,Hari]

Method -2 :

var arr = [Subhu,Mohan,Kannan,Sathish,Hari];
var removeItem = "Kannan";

newArray.splice( $.inArray(removeItem, arr), 1 );

Result:

[Subhu,Mohan,Sathish,Hari]
Method -3 :

var arr = [Subhu,Mohan,Kannan,Sathish,Hari];
var removeItem = "Kannan";

newArray.splice(arr.indexOf(removeItem),1);

Result:

[Subhu,Mohan,Sathish,Hari]

Method -4 :

var arr = [Subhu,Mohan,Kannan,Sathish,Hari];
var removeItem = "Kannan";

arr.remove(removeItem);

Result:

[Subhu,Mohan,Sathish,Hari]
968
like
0
dislike
0
mail
flag

You must LOGIN to add comments