Javascript Array first(criteria)
Array.prototype.first = function (criteria) { if (criteria == null) return this[0]; for (var i = 0; i < this.length; i++) { var item = this[i]; if (criteria(item)) { return item; }//from ww w . j a v a 2s . co m } return null; };