String.prototype.lastIndexOf

Returns the index of the last occurrence of a substring in the string.

Syntax

lastIndexOf(substring, startIndex?)

Parameters

Return value

The index of the last occurrence of the specified substring, or -1 if not found.

Examples

"banana".indexOf("na")
4
"banana".indexOf("no")
-1