Nodejs Array Remove Item removeItem(deleteValue)

Here you can find the source of removeItem(deleteValue)

Method Source Code

Array.prototype.removeItem = function(deleteValue) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] === deleteValue) {
            this.splice(i, 1);//  ww  w  .  ja  v  a2  s  .  c  o m
            i--;
        }
    }
    return this;
};

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

console.log('\n');

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

Related

  1. remove(number)
    function run() {
        var arr = [1, 2, 1, 4, 1, 3, 4, 1, 111, 3, 2, 1, "1"];
        jsConsole.writeLine("The initial array: " + arr);
        arr.remove(1); 
        jsConsole.writeLine("The array with the number 1 removed: " + arr);
    Array.prototype.remove = function (number) {
        for (var i = 0; i < this.length; i++) {
            if (number === this[i]) {
    ...
    
  2. remove(number)
    var example = [1, 4, 5, 3, 6, 4, 7, 3, 2];
    Array.prototype.remove = function(number){
        var editedArray = [],
            index;
        for (index = 0; index < this.length; index += 1) {
            if (this[index] != number) {
                editedArray.push(this[index]);
        return editedArray;
    };
    console.log(example);
    console.log(example.remove(4));
    
  3. remove(numberToRemove)
    Array.prototype.remove = function(numberToRemove) {
        var index,
            len = this.length;
        for (index = 0; index < len; index += 1) {
            if (this[index] === numberToRemove) {
                this.splice(index, 1);
                index -= 1;
    };
    var arr = [1, 2, 5, 54, 32, 1, 4, 4, 1, 1, 1, 54, 3, 65, 4];
    arr.remove(1);
    console.log(arr);
    
  4. removeItem( (item)
    Array.prototype.removeItem = (function (item){
        var newArray = [];
        for (var index in this) {
            if(this[index] !== item && typeof this[index] !== "function") {
                newArray.push(this[index]);
        return newArray;
    });
    ...
    
  5. removeItem()
    Array.prototype.removeItem = function() {
      for (var item in arguments) { 
        for (var i = 0; i < this.length; i++) {
          if (this[i] === arguments[item]) {
            this.splice(i, 1);
    var arr = [1, 2, 1, 4, 1, 3, 4, 1, 111, 3, 2, 1, '1'];
    arr.removeItem(1);
    console.log(arr);
    arr = ['hi', 'bye', 'hello'];
    arr.removeItem('bye');
    console.log(arr);
    
  6. removeItem(el)
    var numberInput = [1, 2, 1, 4, 1, 3, 4, 1, 111, 3, 2, 1, '1'];
    var stringInput = ['hi', 'bye', 'hello' ];
    Array.prototype.removeItem = function (el){
        var newArr = [];
        for (var i = 0; i < this.length; i++) {
            if (this[i] !== el){
                newArr.push(this[i]);
        return newArr;
    console.log(numberInput.removeItem(1));
    console.log(stringInput.removeItem('bye'));
    
  7. 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;
    };
    
  8. 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' ];
    ...
    
  9. 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);
    ...