Javascript Array removeByValue(index,val)

Description

Javascript Array removeByValue(index,val)


Array.prototype.removeByValue = function(index,val) {
    for(var i=0; i<this.length; i++) {
        if(this[i][index] == val) {
            this.splice(i, 1);/*  w  w  w.j  a v a2  s. c  o m*/
            break;
        }
    }
}

var arr = [{first:'zhang',last:'san'},{first:'li',last:'si'}];
arr.removeByValue('first','li');
console.log(arr)



PreviousNext

Related