Javascript Array remove(object)

Description

Javascript Array remove(object)


Array.prototype.remove = function(object) {
    var index = this.indexOf(object);
    if (index >= 0) {
        return this.splice(index, 1);
    }//from  w ww.j  av a2  s. c  om
    else {
        return this;
    }
};

Javascript Array remove(object)

Array.prototype.remove = function(object) {
    var me = this;
    var i;// w  w w.  jav  a2  s  .co  m
    for (i = 0; i <  me.length; i++) {
        if (me[i] == object) {
            me[i] = null;
            me.splice(i,1);
            return;
        }
    }
};

Javascript Array remove(object)

var Random = {/* ww  w .  j ava2 s .  co  m*/
    color: function() {
        return "#" + ((1 << 24) * Math.random() | 0).toString(16);
    }
};

Array.prototype.remove = function(object) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == object) {
            this.splice(i, 1);
            return this;
        }
    }
};

Array.prototype.removeAll = function(what) {
    for (var i = this.length; i--;) {
        if (this[i] === what) {
            this.splice(i, 1);
        }
    }
    return this;
};

Array.prototype.append = function() {
    for (var i = 0; i < arguments.length; i++) {
        this.push(arguments[i]);
    }
    return this;
};

Array.prototype.prepend = function() {
    for (var i = 0; i < arguments.length; i++) {
        this.unshift(arguments[i]);
    }
    return this;
};



PreviousNext

Related