array.prototype.find

Array.prototype.find ES6 polyfill.

MIT 15 个版本
安装
npm install array.prototype.find
yarn add array.prototype.find
pnpm add array.prototype.find
bun add array.prototype.find
README

array.prototype.find Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm 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)

版本列表
2.2.3 2024-03-19
2.2.2 2023-08-27
2.2.1 2022-11-02
2.2.0 2022-04-12
2.1.2 2021-10-01
2.1.1 2020-02-24
2.1.0 2019-05-23
2.0.4 2017-03-30
2.0.3 2017-01-24
2.0.2 2017-01-24
2.0.1 2016-12-13
2.0.0 2016-01-31
1.0.0 2014-08-14
0.1.1 2014-03-24
0.1.0 2013-12-20