JavaScript String lastIndexOf()
JavaScript String lastIndexOf()
The lastIndexOf() method is used to return the index of the last occurrence of a specified value in a string. However, it returns the index from the beginning position i.e, 0. If the value is absent/missing, then the value returned will be -1. This method is case-sensitive and searches from end to beginning.
Syntax:-
Its syntax is:- string.lastIndexOf(searchvalue, start)
Return:-
Its return is:- the position where the search-value occurs else -1
Further Explanation:-
Parameter | Description |
searchvalue | Required. The string to search for. |
start | Optional. The position where to start. |