Get first value by predicate - Node.js Array

Node.js examples for Array:Search

Description

Get first value by predicate

Demo Code


Array.prototype.first = function (predicate) {
    for (var i = 0; i < this.length; ++i) {
        if (predicate(this[i]))
            return this[i];
    }//  www . j  a  va 2  s.co  m
};

Related Tutorials