Removes all occurences of the given element from the list. - Node.js Array

Node.js examples for Array:Remove Element

Description

Removes all occurences of the given element from the list.

Demo Code

/**// ww w . ja  va 2 s.c  om
 * Removes all occurences of the given element from the list.
 *
 * @param element the element to remove.
 */
Array.prototype.removeAll = function(element) {
  for(var i=0; i<this.length; i++) { 
      if(this[i] === element) {
        this.splice(i,1);
        i--;
      }
  }
}

Related Tutorials