jQuery: rimuovere elementi specifici dagli array

Con jQuery possiamo rimuovere un elemento specifico da un array.

jQuery di Gabriele Romanato

Con jQuery possiamo rimuovere un elemento specifico da un array.

La soluzione è la seguente:


(function( $ ) {
  $(function() {
    var arr = [ 1, 2, 3, 4, 5 ];
    var removeItem = 2;   

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

Commenti