Javascript Array toggleValue(value)

Description

Javascript Array toggleValue(value)


Array.prototype.toggleValue = function (value) {
    var index = this.indexOf(value);
    if (index === -1) {
        this.push(value);/*ww w  .  j  a  v  a  2s. com*/
    }
    else {
        this.splice(index, 1);
    }
};



PreviousNext

Related