Nodejs Array Remove Item removeItem(item)

Here you can find the source of removeItem(item)

Method Source Code

Array.prototype.removeItem = function (item) {
    var result = [];

    for (var i = 0; i < this.length; i++) {
        if (this[i] !== item) {
            result.push(this[i]);//from   w  w  w . j a  va 2s .  c o  m
        }
    }

    return result;
};

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

var arr = ['hi', 'bye', 'hello'];
arr = arr.removeItem('bye');
console.log(arr);

Related

  1. removeItem(index)
    Array.prototype.removeItem = function(index) {
      if(isNaN(index) || index > this.length) {
        return false;
        for (var i = 0; i < this.length; i++) {
            if (i > index) {
                this[i-1] = this[i];
        this.length -= 1;
    };
    
  2. removeItem(item)
    Array.prototype.removeItem = function(item){
        while(this.indexOf(item) !== -1) {
            this.splice(this.indexOf(item), 1);
        return this;
    var arr = [1, 2, 1, 4, 1, 3, 4, 1, 111, 3, 2, 1, '1'];
    console.log(arr.removeItem(1));
    var arr = ['hi', 'bye', 'hello' ];
    ...
    
  3. removeItem(item)
    Array.prototype.removeItem = function(item) {
        while (this.indexOf(item) >= 0) {
            this.splice(this.indexOf(item), 1);
        console.log(this);
        return this;
    };
    var arr = [1, 2, 1, 4, 1, 3, 4, 1, 111, 3, 2, 1, '1'];
    arr.removeItem(1);
    ...
    
  4. removeItem(item)
    Array.prototype.removeItem = function(item){
      for (var i = 0; i < this.length; i++) {
        if (this[i] === item) {
          this.splice(i,1);
          i--;
    };
    var arr = [1, 2, 1, 4, 1, 3, 4, 1, 111, 3, 2, 1, '1'];
    ...
    
  5. removeItem(item)
    Array.prototype.removeItem = function(item) {
        var index = this.indexOf(item);
           if(index > -1){
               this.splice(index,1);
        return this;
    };
    var arr = [1, 2, 1, 4, 1, 3, 4, 1, 111, 3, 2, 1, '1'];
    arr = arr.removeItem(1);
    ...
    
  6. removeItem(item)
    Array.prototype.removeItem = function(item) { 
      for(var i = 0, l = this.length; i < l; ++i){
        index = this.indexOf(item);
        if (index > -1) {
          this.splice(index, 1);
      return this;
    
  7. removeItem(item)
    Array.prototype.removeItem = function(item) {
      return this.remove(this.indexOf(item));
    
  8. removeItem(itemToRemove)
    'use strict';
    Array.prototype.removeItem = function (itemToRemove) {
      var index = this.indexOf(itemToRemove);
      var itemFoundInArray = (index != -1);
      if (itemFoundInArray) {
        this.splice(index, 1); 
    };
    
  9. removeItem(item_)
    Array.prototype.removeItem = function(item_) {
        var i = this.indexOf(item_);
        this.splice(i, 1);
    };