indexOf
arrayGets the index at which the first occurrence of value is found in array.
Signature
indexOf<T>(array: T[], value: T, fromIndex?: number): numberParameters
| Name | Type | Description |
|---|---|---|
array | T[] | The array to inspect |
value | T | The value to search for |
fromIndex? | number | The 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:
1With fromIndex
import { indexOf } from 'dashlite'
const result = indexOf([1, 2, 1, 2], 2, 2)
console.log(result)Output:
3Available since version 1.0.0