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

The offset of a substring within the string.

Arguments

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

Description

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){
    oLocations.push(loc);
    loc = sentence.lastIndexOf('o',loc-1);
}
// ** oLocations is [42,27,17,12]

var url = "http://phrogz.net/ObjJob//js/methods";
var path = url.substring( 0 , url.lastIndexOf('/')+1 );
// ** path is "http://phrogz.net/ObjJob/"