array.prototype.find
Simple ES6 Array.prototype.find polyfill for older environments taken from es6-shim.
For browsers and node.js.
Installation
- Just include repo before your scripts.
npm install array.prototype.find
Usage
Array.prototype.find(predicate[, thisArg])
returns first item that matches predicate
function.predicate(value, index, collection)
: takes three arguments
value
: current collection elementindex
: current collection element indexcollection
: the collection
var find = require('array.prototype.find');
find([1, 2], function (x) { return x === 2; });
require('array.prototype.find').shim();
Code example:
[1, 5, 10, 15].find(function (a) { return a > 9; })
Acknowledgements
Tests, fixes, and travis support added by _duncanhall
License
The MIT License (c) 2016 Paul Miller (http://paulmillr.com)