Simple ES6 Array.prototype.find polyfill for older environments taken from MDN.
For browsers only, bower-friendly. Explicitly not meant to be used with node, use Array.prototype.find if you wish a shim for node.
- Just include repo before your scripts.
bower install mdn-array.prototype.find
Array.prototype.find(predicate[, thisArg])
returns first item that matchespredicate
function.
predicate(value, index, collection)
: takes three argumentsvalue
: current collection elementindex
: current collection element indexcollection
: the collection
thisArg
: Optional. Object to use asthis
when executingpredicate
.
[1, 5, 10, 15].find(function (a) { return a > 9; }) // 10
Tests, readme and travis support gratefully taken from Array.prototype.find
CC0 1.0