Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

find-index

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-index

finds an item in an array matching a predicate function, and returns its index

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
712K
decreased by-28.85%
Maintainers
1
Weekly downloads
 
Created

What is find-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.

What are find-index's main functionalities?

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

Other packages similar to find-index

Keywords

FAQs

Package last updated on 12 Feb 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc