15.5.4.8 String.prototype.lastIndexOf(searchString, position)

2010-07-10

int String.prototype.lastIndexOf(searchString:string|mixed, position:uint|mixed=0)

Return the last occurrence of searchString in this string value, both coerced to string. If position is given, it is coerced to int and the search will start from len-start (so start positions from the right).

String.prototype.lastIndexOf.length = 1

Code: (Meta Ecma)
String.prototype.lastIndexOf = function(searchString, position){
CheckObjectCoercible(this);
var S = ToString(this);
var searchStr = ToString(searchString);
var numPos = ToNumber(position);
if (position === undefined) numPos = 0;
var len = S.length;
var start = Math.min(Math.max(pos, 0), len);
// no specific algorithm is given, many exist
// should return the last position where search
// was (completely) found
return S.lastIndexOf(searchStr, numPos);
}