lastIndexOf

array

This method is like indexOf except that it iterates over elements of array from right to left.

Signature

lastIndexOf<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 from

Returns

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

Examples

Basic usage

import { lastIndexOf } from 'dashlite'

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

Output:

3

Available since version 1.0.0