Removes the first occurrence of the given element from the list. - Node.js Array

Node.js examples for Array:Remove Element

Description

Removes the first occurrence of the given element from the list.

Demo Code

/**/*from w w w  .jav a 2s .  co m*/
 * Removes the first occurrence of the given element from the list.
 *
 * @param element the element to remove.
 * @return whether the operation was successfull or not.
 */
Array.prototype.remove = function(element) {
  for(var i=0; i<this.length; i++) { 
      if(this[i] === element) {
        this.splice(i,1);
        return true;
      }
  }

  return false; 
}

Related Tutorials