Javascript Array removeByValue(val)

Description

Javascript Array removeByValue(val)


Array.prototype.removeByValue = function(val) {
    for(var i=0; i<this.length; i++) {
        if(this[i] == val) {
            this.splice(i, 1);//from  w ww  . jav  a 2s.  c  o m
            break;
        }
    }
}

Javascript Array removeByValue( val )



/**//  ww w .  jav  a  2s  . c  o m
 * Function to remove values from arrays
 *
 * @param {Array} this.elements or this.fields
 *
 * @returns {undefined}
 */
Array.prototype.removeByValue = function( val ) {
    for ( var i=0; i < this.length; i++ ) {
        if ( this[i] == val ) {
            this.splice( i, 1 );
            break;
        }
    }
};



PreviousNext

Related