Javascript Array removeItem(el)

Description

Javascript Array 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]);//w  ww .  j a v  a 2 s.c o m
        }
    }

    return newArr;
}


console.log(numberInput.removeItem(1));
console.log(stringInput.removeItem('bye'));



PreviousNext

Related