Posted By

gustavopaes on 04/24/09


Tagged

array jquery


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

gurjeetsaini
danielfilho
indamix
suibhne


Remove item from array with jQuery


 / Published in: JavaScript
 

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

  1. arr = [1, 2, 3, 4, 5] // array inicial
  2. var removeItem = 2; // item do array que deverá ser removido
  3.  
  4. arr = jQuery.grep(arr, function(value) {
  5. return value != removeItem;
  6. });
  7.  
  8. // new array
  9. // [1, 3, 4, 5]

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: nchutchind on February 2, 2010

Line 4 is incorrect, as it has an extra closing parenthesis.

arr = jQuery.grep(arr, function(value)) { should be arr = jQuery.grep(arr, function(value) {

Posted By: gustavopaes on September 19, 2010

Fixed, thanks

You need to login to post a comment.