Javascript Array removeAll(item)

Description

Javascript Array removeAll(item)


/*/*from  w  ww.ja  v a  2  s  . co  m*/
 * Insert in an array for adtnl capability.
 */
Array.prototype.removeAll = function(item) {
  var removed = [];
  for (var i = 0, x = this.length; i < x; i++) {
    if (this[i] === item) {
      removed.push(item);
      this.splice(i, 1);
    }
  }
  return removed;
}

Javascript Array removeAll(item)

Array.prototype.removeAll = function (item) {
 var index = -1; 

 do {/*from   ww  w  .j a  va 2 s .c o m*/
  index = this.remove(item);
 } while (index >= 0)
}



PreviousNext

Related