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 Parameter | Type | Description |
---|---|---|
array | Array | The array to inspect |
value | any | The value to search |
lastSearchIndex (optional) | number | The index to search from |
Return value
Type |
---|
number |
Sample
Example | Result | Description |
---|---|---|
lastIndexOf([1, 10, 1, 10], 10) | 3 | Returns the last index of value 10 |
lastIndexOf([1, 10, 1, 10], 10, 2) | 1 | Returns the last index of value 10 for search index up to 2 |
lastIndexOf([1, 10, 1, 10], 20) | -1 | Returns -1 for search value of 20 |
To view all the List functions, click here.
See Also
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article