Remove item from array with jQuery


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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

You need to login to post a comment.