indexOf

array

Gets the index at which the first occurrence of value is found in array.

Signature

indexOf<T>(array: T[], value: T, fromIndex?: number): number

Parameters

NameTypeDescription
arrayT[]The array to inspect
valueTThe value to search for
fromIndex?numberThe index to search fromDefault: 0

Returns

number - Returns the index of the matched value, else -1

Examples

Basic usage

import { indexOf } from 'dashlite'

const result = indexOf([1, 2, 1, 2], 2)
console.log(result)

Output:

1

With fromIndex

import { indexOf } from 'dashlite'

const result = indexOf([1, 2, 1, 2], 2, 2)
console.log(result)

Output:

3

Available since version 1.0.0