Skip to content

findIndex ​

The findIndex() method returns the index of the first element of an array that satisfies a given condition.

Interactive example ​

Syntax ​

Classic signature ​

typescript
function findIndex<
	GenericInput extends readonly unknown[]
>(
	input: GenericInput, 
	predicate: (
		element: GenericInput[number], 
		params: ArrayFindIndexParams
	) => boolean
): number | undefined

Curried signature ​

typescript
function findIndex<
	GenericInput extends readonly unknown[]
>(
	predicate: (
		element: GenericInput[number], 
		params: ArrayFindIndexParams
	) => boolean
): (input: GenericInput) => number | undefined

Helper parameters ​

typescript
interface ArrayFindIndexParams {
	index: number;
}

Parameters ​

  • input: The array to search in.
  • predicate: Predicate function that tests each element. Receives the element and an object containing the index.
  • params.index: Position of the current element in the array.

Return value ​

The index of the first element that satisfies the condition, or undefined if no element matches.

See also ​

  • find - Returns the element instead of the index
  • findLastIndex - Finds the index of the last element

Sources ​

Released under the MIT license.