Array

Array.prototype.findIndex

Returns the index of the first element in an array that satisfies the provided testing function

Syntax

JavaScript
array.findIndex(callbackFn, thisArg?)

Parameters

ParameterTypeDescription
callbackFn(element, index, array) => booleanFunction to test each element
thisArganyValue to use as this when executing callbackFn

Return Value

The index of the first matching element, or -1 if no element matches

Examples

Basic Usage
const numbers = [5, 12, 8, 130];
const idx = numbers.findIndex(n => n > 10);
console.log(idx); // 1
Practical Example
const users = [
  { name: 'Alice', active: false },
  { name: 'Bob', active: true }
];
const activeIdx = users.findIndex(u => u.active);
console.log(activeIdx); // 1
Advanced Usage
const letters = ['a', 'b', 'c', 'd'];
const idx = letters.findIndex(l => l === 'z');
console.log(idx); // -1

Understanding Array.prototype.findIndex

The Array.prototype.findIndex method in JavaScript returns the index of the first element in an array that satisfies the provided testing function. It belongs to the Array object and is one of the most widely used methods for working with array values in modern JavaScript and TypeScript applications.

The method signature is array.findIndex(callbackFn, thisArg?). It accepts 2 parameters: callbackFn, thisArg. When called, it returns the index of the first matching element, or -1 if no element matches. Understanding when and how to use findIndex() helps you write more expressive, readable code.

Common use cases for Array.prototype.findIndex include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like array-find, array-indexof, array-findlastindex, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Array.prototype.findIndex is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Array Methods

Other methods in the Array object

Related Tools

More Array Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.