Skip to content

lastIndexOf

The lastIndexOf() method returns the index of the last occurrence of an element in an array.

Interactive example

Syntax

Classic signature

typescript
function lastIndexOf<
	GenericElement extends unknown
>(
	input: readonly GenericElement[], 
	element: GenericElement, 
	fromIndex?: number
): number | undefined

Curried signature

typescript
function lastIndexOf<
	GenericElement extends unknown
>(
	element: GenericElement
): (input: readonly GenericElement[]) => number | undefined

Parameters

  • input: The array to search in.
  • element: The element to search for.
  • fromIndex: Starting index for the reverse search (optional).

Return value

The index of the last occurrence of the element, or undefined if the element is not found.

See also

  • indexOf - Returns the index of the first occurrence
  • findLastIndex - Finds the last index with a condition

Sources

Released under the MIT license.