String Function - lastIndexOf
: StringMethod or Function
: This method is similar to indexOf() function and takes a character or string as an argument. Searches the given string in the main string and returns the last occurrence position of the string. Returns -1 if the search string is not present in the main string.
var ss = "a last index test ";
var result = ss.lastIndexOf("e");
In the above example,
- the main string is stored in a variable ss.
- the method take a character "e" as argument.
- the method searches in main string (ss) for the search string "e".
- "e" is at two positions 10 and 14. last occurrence value 14 is returned as result.