Javascript Array find(validator)

Description

Javascript Array find(validator)


Array.prototype.find = function(validator) {
    var result = undefined;
    var count = this.length;

    for(var i = 0; i < count; i++) {
        var current = this[i];
        //  w  w w .  j  a v  a 2s .c  o m
        if(validator(current)) {
            result = current;
            break;
        }
    }

    return result;
}



PreviousNext

Related