I really dont understand how lastIndexOf works. I could not get the usage of second optional parameter.
string.lastIndexOf(searchvalue,start)
searchvalue -> Required. The string to search for
start -> Optional. The position where to start the search. If omitted, the default value is the length of the string
var test = "mississippi";
test.lastIndexOf("ss",1) // return -1
test.lastIndexOf("ss",2) // returns 2
test.lastIndexOf("ss",5) // returns 5
Could anyone tell me the idea step by step ? Why first one returns -1 and second one returns 2 for example ?
TIA