Javascript Array removeAll(obj)

Description

Javascript Array removeAll(obj)


// ArrayExtension.js
// Copyright 2007 Ben Kazez
// Adds handy capabilities to Array.
////from   w  ww  .j a va2  s  .c o m

/* Removes all occurrences of obj
 */
Array.prototype.removeAll = function(obj) {
 var newArr = new Array();
 var len = this.length;
 for(var i = 0; i < len; i++) {
  if(this[i] != obj)
   newArr.push(this[i]);
 }
 this = newArr;
 return this;
}



PreviousNext

Related