Standard built-ins

String.prototype.lastIndexOf()

Try the free JavaScript compiler

Finds the last literal match whose starting index does not exceed the normalized position.

Formal Syntax & Structure

javascript syntaxjavascript
text.lastIndexOf(searchString, [position])

Parameters & Attributes

NameTypeDescription
searchStringStringLiteral sequence to locate.
positionNumberLargest permitted start index; default searches from the end.

Return Value

Number

Code-unit index or -1.

Working Example

Example Snippetjavascript
console.log("banana".lastIndexOf("ana"));
JavaScript Reference