List of utility methods to do Array First Predicate
first(predicate)Array.prototype.first = function (predicate) { for (var i = 0; i < this.length; ++i) { if (predicate(this[i])) return this[i]; }; | |
first(predicate, def)Array.prototype.first = function (predicate, def) { var l = this.length; if (!predicate) return l ? this[0] : def == null ? null : def; for (var i = 0; i < l; i++){ if (predicate(this[i], i, this)) return this[i]; return def == null ? null : def; }; ... |