Skip to content

findLastIndex

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

Interactive example

Syntax

Classic signature

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

Curried signature

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

Helper parameters

typescript
interface ArrayFindLastIndexParams {
	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 last element that satisfies the condition, or undefined if no element matches.

See also

  • findLast - Returns the element instead of the index
  • findIndex - Finds the index of the first element

Sources

Released under the MIT license.