Skip to content

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 | undefined

Curried signature

typescript
function indexOf<
	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 search (optional).

Return value

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

See also

Sources

Released under the MIT license.