Array.prototype.find

Simple ES6 Array.prototype.find polyfill for older environments.

MIT License

Downloads
8.3M
Stars
38
Committers
11

array.prototype.find Version Badge

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 element
    • index: current collection element index
    • collection: the collection
// as a function
var find = require('array.prototype.find');
find([1, 2], function (x) { return x === 2; }); // 2

// to shim it
require('array.prototype.find').shim();

Code example:

// Default:
[1, 5, 10, 15].find(function (a) { return a > 9; }) // 10

Acknowledgements

Tests, fixes, and travis support added by _duncanhall

License

The MIT License (c) 2016 Paul Miller (http://paulmillr.com)

Package Rankings
Top 27.55% on Repo1.maven.org
Top 2.12% on Npmjs.org
Top 6.75% on Proxy.golang.org
Top 11.78% on Bower.io
Badges
Extracted from project README
Version Badge github actions coverage dependency status dev dependency status License Downloads npm badge