Learn JavaScript
String Methods

Finding Last Index of Character in String

The lastIndexOf() method helps us find the last instance of a string inside another.

It accepts two arguments - a substring and a position. The method looks for the substring starting from the end of the main string. It returns the position at which the string is found first, beginning from the end.

If there are no matches, it returns -1.