lastIndexOf

Modified on Mon, 07 Aug 2023

Description

Get the index at which the last occurrence of value is found in array, else -1

Syntax

lastIndexOf(array, value, lastSearchIndex)

Parameters

Input ParameterTypeDescription
arrayArrayThe array to inspect
valueanyThe value to search
lastSearchIndex (optional)numberThe index to search from

Return value

Type
number

Sample

ExampleResultDescription
lastIndexOf([1, 10, 1, 10], 10)3Returns the last index of value 10
lastIndexOf([1, 10, 1, 10], 10, 2)1Returns the last index of value 10 for search index up to 2
lastIndexOf([1, 10, 1, 10], 20)-1Returns -1 for search value of 20

To view all the List functions, click here.

See Also