Nodejs Array Remove by Value removeItem(value)

Here you can find the source of removeItem(value)

Method Source Code

Array.prototype.removeItem = function (value) {
    for (i = 0; i < this.length; i++) {
        if (this[i] === value) {
            this.splice(i, 1);/*from w  w  w.j  a  va 2 s .  com*/
        }
    }
}

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

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

Related

  1. removeElement(valueElement)
    Array.prototype.removeElement = function(valueElement){
        for(var i = this.length - 1; i >= 0; i-=1) {
            if(this[i] === valueElement) {
                this.splice(i, 1);
    };
    var arr=[1,1,1,1,1,3,5,6,7,8,9];
    arr.removeElement(1);
    ...
    
  2. removeElement(element)
    Array.prototype.removeElement = function(element) {
      var idx = this.indexOf(element);
      if (idx <= (-1)) {
        return;
      return this.remove(idx);
    };
    
  3. removeElementremoveElement(element)
    var arr = [1,2,1,4,1,3,4,1,111,3,2,1,'1'];
    Array.prototype.removeElement = function removeElement(element){
        for (var i = 0; i < arr.length; i+=1) {
            if(arr[i]===element){
                arr.splice(i,1)
        return arr;
    };
    ...
    
  4. removeElements(elements)
    Array.prototype.removeElements = function (elements) {
      elements.forEach((el) => {
        this.splice(this.indexOf(el), 1)
      })
    
  5. removeItem(value)
    Array.prototype.removeItem = function (value) {
        for (var i in this) {
            if(this[i] === value){
                this.splice(i, 1);
        return this;
    };
    var arr = [1, 2, 1, 4, 1, 3, 4, 1, 111, 3, 2, 1, '1'];
    ...
    
  6. removeItem(value)
    Array.prototype.removeItem = function (value) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] === value) {
                this.splice(i, 1);
        return this;
    var arr = [1, 2, 1, 4, 1, 3, 4, 1, 111, 3, 2, 1, '1'];
    ...
    
  7. removeItem(value)
    Array.prototype.removeItem = function(value) {
        var result = [];
        for (var i = 0; i < this.length; i++) {
            if (this[i] === value) {
                this.splice(i, 1);
        return this;
    };
    ...
    
  8. removeItem(value)
    Array.prototype.removeItem = function (value) {
        var result = [];
        for (var i = 0; i < this.length; i++) {
            if (this[i] === value) {
                this.splice(i, 1); 
        return this;
    };
    ...
    
  9. removeItem(value)
    Array.prototype.removeItem = function (value) {
        var len = this.length;
        var resultArr = [];
        for (var i = 0; i < len; i++) {
            if (this[i] !== value) {
                resultArr.push(this[i]);
        return resultArr;
    ...