Javascript Array pull(item)

Description

Javascript Array pull(item)


/**/*ww  w  .  j  av a 2 s . co m*/
 * Make property non-enumerable.
 */
Object.defineProperty(Array.prototype, 'pull', {
 enumerable:false,
 writable:true,
 configurable:true
});

/**
 * Removes the passed item from an array, the opposite of push().
 * @param item
 * @return {*}
 */
Array.prototype.pull = function (item) {
 var index = this.indexOf(item);
 if (index > -1) {
  this.splice(index, 1);
  return index;
 } else {
  return -1;
 }
};



PreviousNext

Related