
Research
Security News
Malicious npm Packages Use Telegram to Exfiltrate BullX Credentials
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
finds an item in an array matching a predicate function, and returns its index
The find-index npm package is a utility that helps you find the index of the first element in an array that satisfies a provided testing function. It is useful for quickly locating elements in arrays without having to write custom loops.
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 checks for elements greater than 13, and the first such element is at index 3.
const findIndex = require('find-index');
const array = [5, 12, 8, 130, 44];
const isLargeNumber = (element) => element > 13;
const index = findIndex(array, isLargeNumber);
console.log(index); // Output: 3
Find index with custom predicate
This feature allows you to use a custom predicate function to find the index of the first element that matches the condition. In this example, the predicate checks for a user with the name 'Jane', which is found at index 1.
const findIndex = require('find-index');
const users = [
{ id: 1, name: 'John' },
{ id: 2, name: 'Jane' },
{ id: 3, name: 'Jack' }
];
const predicate = (user) => user.name === 'Jane';
const index = findIndex(users, predicate);
console.log(index); // Output: 1
Lodash is a popular utility library that provides a wide range of functions for common programming tasks, including array manipulation. The `_.findIndex` method in Lodash offers similar functionality to the find-index package, allowing you to find the index of the first element in an array that matches a given predicate.
The array-find-index package is another utility that provides a similar function to find-index. It is a lightweight package that offers a method to find the index of the first element in an array that satisfies a provided testing function. It is similar in scope and usage to find-index.
An implementation of the ES6 method Array.prototype.findIndex
as a standalone module and a
ponyfill.
Finds an item in an array matching a predicate function, and returns its index.
Fast both when thisArg
is used and also when it isn't.
npm install find-index
var findIndex = require('find-index/findIndex')
var findIndex = require('find-index/ponyfill') // will use native Array#findIndex if available.
var findLastIndex = require('find-index/findLastIndex') // search backwards from end
findIndex(array, callback[, thisArg])
findLastIndex(array, callback[, thisArg])
Parameters:
array
The array to operate on.
callback
Function to execute on each value in the array, taking three arguments:
element
The current element being processed in the array.
index
The index of the current element being processed in the array.
array
The array findIndex was called upon.
thisArg
Object to use as this when executing callback.
Based on array-findindex
$ iojs --harmony_arrays perf/benchmark.js
native Array.prototype.findIndex: 6347ms
findIndex: 1633ms
findIndex ponyfill: 6384ms
findLastIndex: 1508ms
npm lodash.findindex: 2900ms
npm array-findindex: 3512ms
[1.1.1] - 2019-02-12
FAQs
finds an item in an array matching a predicate function, and returns its index
The npm package find-index receives a total of 595,731 weekly downloads. As such, find-index popularity was classified as popular.
We found that 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.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.
Security News
AI-generated slop reports are making bug bounty triage harder, wasting maintainer time, and straining trust in vulnerability disclosure programs.