JavaScript lastIndexOf() Method

The JavaScript lastIndexOf() method returns the position of the last occurrence of a specified value in a string.

Syntax:

string.lastIndexOf(searchvalue,start)

Where,
Searchvalue=Required. The string to search for
start=Optional. The position where to start the search which isĀ  searching from backwards. If omitted, the default value is the length of the string

Example:

var str=”This is a demo for JavaScript lastIndexOf() Method.
The JavaScript lastIndexOf() method is case sensitive!”;
var n=str.lastIndexOf(“lastIndexOf()”);
alert(n);

Live Demo: JavaScript lastIndexOf() Method

Leave a Reply