Nodejs Array Remove Item remove(item)

Here you can find the source of remove(item)

Method Source Code

Array.prototype.remove = function(item){
   var index;//from  w  ww  .j  ava 2 s.  com
   while(1){
      index=this.indexOf(item);
      if (index > -1) {
         this.splice(index, 1);   
          console.log(this);   
      }else{
         break;
      }
   }
};

var arr = [1,2,1,4,1,3,4,1,111,3,2,1,'1'];
document.getElementById("input").innerHTML=arr;
document.getElementById("check").addEventListener('click', function(){
   arr.remove(1);
   document.getElementById("result").innerHTML = arr + " See more result on the browser console";
});

Related

  1. remove(item)
    Array.prototype.remove = function(item) {
        var idx = this.indexOf(item);
        if( idx != -1 )
            this.splice(idx, 1);
        return this;
    
  2. remove(item)
    var sampleArray = [1, 2, 1, 4, 1, 3, 4, 1, 111, 3, 2, 1,'1'];
    Array.prototype.remove = function (item) {
        while (this.indexOf(item) >= 0) {
            this.splice(this.indexOf(item), 1);
        return this;
    };
    console.log(sampleArray.remove(1));
    
  3. remove(item)
    Array.prototype.remove = function(item){
      var arr = this.slice(0);
      for(var i=0;i<arr.length;i++){
        if(arr[i] == item){
          arr.splice(i,1);
          i--;
      return arr;
    ...
    
  4. remove(item)
    Array.prototype.remove = function(item) {
      var i = $.inArray(item, this);
      if (i === undefined || i < 0) return undefined;
      return this.splice(i, 1);
    };
    
  5. remove(item)
    Array.prototype.remove = function (item) {
        if (item == null)
            return;
        var index = -1;
        for (var i = 0; i < this.length; i++) {
            if (this[i] == item) {
                index = i;
                break;
        if (index >= 0)
            this.splice(i, 1);
    };
    
  6. remove(item)
    Array.prototype.remove = function(item) {
        var i,
            len;
        for (i = 0, len = this.length; i < len; i += 1) {
            if (this[i] === item) {
                this.splice(i, 1);
                i -= 1;
        return this;
    };
    var arr = [1, 2, 1, 4, 1, 1, 3, 4, 1, 111, 3, 2, 1, '1'];
    console.log('Original array');
    console.log(arr);
    console.log(arr.length);
    console.log('Modified array without removed elements');
    console.log(arr.remove(1));
    console.log(arr.length);
    
  7. remove(item)
    Array.prototype.remove = function(item) {
      var index;
      while ((index = this.indexOf(item)) !== -1) {
        this.splice(index, 1);
      return this;
    };
    
  8. remove(item)
    Array.prototype.remove = function(item){
      var i = this.indexOf(item);
      return this.splice(i, 1);
    
  9. remove(item)
    Array.prototype.remove = function(item) {
      var index;
      index = this.indexOf(item);
      if (index >= 0) {
        return this.splice(index, 1)[0];
      } else {
        return null;
    };
    ...