indexOf
The indexOf() method returns the index of the first occurrence of an element in an array.
Interactive example
Syntax
Classic signature
typescript
function indexOf<
GenericElement extends unknown
>(
input: readonly GenericElement[],
element: GenericElement,
fromIndex?: number
): number | undefinedCurried signature
typescript
function indexOf<
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 search (optional).
Return value
The index of the first occurrence of the element, or undefined if the element is not found.
See also
lastIndexOf- Returns the index of the last occurrencefindIndex- Finds the index with a condition
