Javascript Array remove(el)

Description

Javascript Array remove(el)


let arr = [1,2,1,4,1,3,4,1,111,3,2,1,'1'];

Array.prototype.remove = function(el){
  let elements = [].slice.apply(this),
    result = elements.filter(function(a){
      if(a !== el){
        return console.log(a);
      }/*  w  w  w. j  a v  a2 s . c  om*/
    });
  return result;
};

arr.remove(1);

Javascript Array remove(el)

Array.prototype.remove = function(el) {
  var i = this.indexOf(el);

  if (i != -1) {/*  www . ja v  a2s  .c  o m*/
    this.splice(i, 1);
  }

  return this;
};

Javascript Array remove(el)

Array.prototype.remove = function (el) {
    var index = this.indexOf(el);
    if (index > -1) {
        this.splice(index, 1);//from  w w  w . j ava 2 s  .  c o  m
    }
};



PreviousNext

Related