
Security News
GitHub Actions Supply Chain Attack Puts Thousands of Projects at Risk
A compromised GitHub Action exposed secrets in CI/CD logs, putting thousands of projects at risk and forcing developers to urgently secure their workflows.
array-find-index
Advanced tools
The array-find-index npm package provides a simple utility to find the index of the first element in an array that satisfies a provided testing function. It is a lightweight and straightforward alternative to the native Array.prototype.findIndex method, particularly useful in environments where polyfills are not available or desired.
Find Index of First Matching Element
This feature allows you to find the index of the first element in an array that satisfies the provided testing function. In this example, the function isLargeNumber checks if an element is greater than 13, and findIndex returns the index of the first element that meets this condition.
const findIndex = require('array-find-index');
const array = [5, 12, 8, 130, 44];
const isLargeNumber = (element) => element > 13;
const index = findIndex(array, isLargeNumber);
console.log(index); // Output: 3
Lodash is a popular utility library that provides a wide range of functions for common programming tasks. The lodash.findindex method is similar to array-find-index, offering the ability to find the index of the first element in an array that matches a given predicate. Lodash is more feature-rich and includes many other utilities, making it a heavier dependency compared to array-find-index.
This package is a polyfill for the native Array.prototype.findIndex method, which is available in modern JavaScript environments. It provides the same functionality as array-find-index but is intended for use in environments where the native method is not available. It is a direct drop-in replacement for the native method.
ES2015
Array#findIndex()
ponyfill
$ npm install --save array-find-index
const arrayFindIndex = require('array-find-index');
arrayFindIndex(['rainbow', 'unicorn', 'pony'], x => x === 'unicorn');
//=> 1
Same as Array#findIndex()
, but with the input array as the first argument.
MIT © Sindre Sorhus
FAQs
ES2015 `Array#findIndex()` ponyfill
We found that array-find-index demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A compromised GitHub Action exposed secrets in CI/CD logs, putting thousands of projects at risk and forcing developers to urgently secure their workflows.
Research
Security News
A malicious Maven package typosquatting a popular library is secretly stealing OAuth credentials on the 15th of each month, putting Java developers at risk.
Security News
Socket and Seal Security collaborate to fix a critical npm overrides bug, resolving a three-year security issue in the JavaScript ecosystem's most popular package manager.