Tuesday, February 15, 2011

Remove item from array with jQuery

Remove item (number or string) from array, using jQuery (method grep).



arr = [1, 2, 3, 4, 5] // array initial
var removeItem = 2;   // item do array que deverá ser removido


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


// new array

2 comments:

Roy said...

It is exactly what I was looking for. I could simply copy paste it. Thanks for sharing this. I would love to see more posts from you. You should consider updating your blog regularly.


Roy


seo philadelphia

Website Name said...

Can any one know about online listing (any one can input in live site like- name, mobile number,date and this input show in live) and show the input in that site live through a plugin in wordpress.

Website IT