![]() |
VOOZH | about |
The JavaScript Array lastIndexOf() Method is used to find the index of the last occurrence of the search element provided as the argument to the function.
array.lastIndexOf(element, start)This method accepts two parameters as mentioned above and described below:
This method returns the index of the last occurrence of the element. If the element cannot be found in the array, then this method returns -1.
Example 1: Below is an example of the Array lastIndexOf() method.
Output:
0Example 2: In this example, the method will be searched for element 2 in that array and return that element index.
Output:
1Example 3: In this example, the method will search for the element 9 in that array if not found then return -1.
Output:
-1We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete reference article.
The browsers supported by JavaScript Array lastIndexOf() method are listed below: