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 | undefinedCurried signature
typescript
function lastIndexOf<
GenericElement extends unknown
>(
element: GenericElement
): (input: readonly GenericElement[]) => number | undefinedParameters
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 occurrencefindLastIndex- Finds the last index with a condition
