1. array.prototype.find
Array.prototype.find ES6 polyfill.
array.prototype.find
Package: array.prototype.find
Created by: paulmillr
Last modified: Tue, 19 Mar 2024 05:08:35 GMT
Version: 2.2.3
License: MIT
Downloads: 8,299,398
Repository: https://github.com/paulmillr/Array.prototype.find

Install

npm install array.prototype.find
yarn add array.prototype.find

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)

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin