![]() |
VOOZH | about |
The Array.prototype.lastIndexOf() method in TypeScript is used to find the last index at which a given element can be found in the array, searching backwards from the fromIndex. It returns the index of the found element, or -1 if the element is not present.
Syntax:
array.lastIndexOf(searchElement[, fromIndex])Parameter: This method accepts two parameter as mentioned above and described below:
Return Value: This method returns the index of the found element from the last.
Below examples illustrate the Array lastIndexOf() method in TypeScript.
In this example, we will demonstrate the basic usage of the lastIndexOf() method to find the last occurrence of an element in an array.
Output:
3
Example 2:
Output:
3
1 2