lastIndexOf() method returns the index (position) of the last occurrence of a specified value in a string.
syntax ↴
lastIndexOf(searchString, start) ↴
searchString Substring to search for. All values are coerced to strings.
start (optional). The index of the last occurrence of the specified substring at a position less than or equal to start position, which defaults to +Infinity.
lastIndexOf() method searches the string from the end to the beginning.
lastIndexOf() method returns the index from the beginning (position 0).
lastIndexOf() method returns -1 if the value is not found.
lastIndexOf() method is case sensitive.
String to be searched for (searchString) must be a string and cannot be a regex.
You can use a start index (position) where the searchString is expected to start from. Default start position is 0.
If start position is greater than the length of the calling string, the method searches the entire string.
If start position is less than 0 method looks for the specified substring only at index 0.
myString.lastIndexOf(searchString)
myString.lastIndexOf(searchString, start)