myString.lastIndexOf( searchString, [ position ] ) in ECMAScript 262

The offset of a substring within the string.


searchString String The substring to search for wi
position Number [optional] The position to start searchin
Return Type


Like String.indexOf(), this search is case sensitive, and returns -1 if the search string cannot be found. Unlike that method, this method begins its search from the end of the string (or position, if it is smaller) and searches backwards.

var sentence="The quick brown fox jumped over the lazy dog.";
var oLocations = [];
loc = sentence.lastIndexOf('o');
while (loc!=-1){
    loc = sentence.lastIndexOf('o',loc-1);
// ** oLocations is [42,27,17,12]

var url = "";
var path = url.substring( 0 , url.lastIndexOf('/')+1 );
// ** path is ""