array-find
ES6 Array.find ponyfill. Return the first array element which satisfies a testing function.
Last updated 11 years ago by dubban .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install array-find 
SYNC missed versions from official npm registry.

array-find

Build Status

ES 2015 Array.find ponyfill.

Ponyfill: A polyfill that doesn't overwrite the native method.

Find array elements. Executes a callback for each element, returns the first element for which its callback returns a truthy value.

Usage

var find = require('array-find');
var numbers = [1, 2, 3, 4];

find(numbers, function (element, index, array) {
  return element === 2;
});
// => 2

var robots = [{name: 'Flexo'}, {name: 'Bender'}, {name: 'Buster'}];

find(robots, function (robot, index, array) {
  return robot.name === 'Bender';
});
// => {name: 'Bender'}

find(robots, function (robot, index, array) {
  return robot.name === 'Fry';
});
// => undefined

Optionally pass in an object as third argument to use as this when executing callback.

Install

$ npm install array-find

License

MIT

Current Tags

  • 1.0.0                                ...           latest (11 years ago)

4 Versions

  • 1.0.0                                ...           11 years ago
  • 0.1.1                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
  • 0.0.1                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 72
This Month 101
Last Day 11
Last Week 43
Last Month 187
Dependencies (0)
None
Dev Dependencies (1)

Copyright 2013 - present © cnpmjs.org | Home |