Javascript Array remove(num)

Description

Javascript Array remove(num)


Array.prototype.remove = function(num) {
  this[num] = null;/*from  w  ww . j  a va  2s. c om*/
  return this;
};

Javascript Array remove(num)

Array.prototype.remove = function(num) {
    let ax/*from  w  w w  .  j  ava 2s  .c o m*/
    while ((ax = this.indexOf(num)) !== -1) {
            this.splice(ax, 1);
        }
    return this
}

var arr = [1,2,1,4,1,3,4,1,111,3,2,1,1]
arr.remove(1);
console.log(arr);



PreviousNext

Related