Removes the passed item from an array, the opposite of push(). - Node.js Array

Node.js examples for Array:Remove Element

Description

Removes the passed item from an array, the opposite of push().

Demo Code


Array.prototype.pull = function (item) {
  var index = this.indexOf(item);
  if (index > -1) {
    this.splice(index, 1);/* w w  w  . j  a v a2 s  .  co m*/
    return index;
  } else {
    return -1;
  }
};

Related Tutorials