Javascript String LastIndexOf Function
In JavaScript, String Object provides a function lastIndexOf that is most often used to get the last position of specified string pattern passed to the lastIndexOf function. JavaScript lastIndexOf function returns the index position for the last occurrence of specified string pattern in the provided string. By default lastIndexOf function starts searching from last index of the string i.e. equal to the length of the string. If you will pass the optional parameter of start index then it starts searching the string from the specified index.
JavaScript String Object Examples:
You can see the live samples and examples of JavaScript String Object from the following links:
Syntax for Javascript lastIndexOf function
Object.lastIndexOf(substring, startIndex);
Above syntax of javascript lastIndexOf function shows that the function accepts 2 types of parameters:
1. substring: substring parameter of lastIndexOf function accepts the string type value whose last index is to be searched from the given string expression.
2. startIndex: optional: startIndex parameter accepts the integer value to specify the start position for the lastIndexOf function. As javascript lastIndexOf function starts searching from the right side of the string, startIndex parameter value should be equal to or less than the length of the given string. It searched from the specified index upto first index of the string i.e. first character of the given string.
Example 1
var myString = new String();
myString = "Javascript lastIndexOf Function";
document.write(myString.lastIndexOf("i"));
Example 2
document.write(myString.lastIndexOf("i", myString.length));
Example 3
document.write(myString.lastIndexOf("i", myString.lastIndexOf("i") - 1));
Output:
You can see the output of above discussed code from the following links:
Continue to next tutorial: JavaScript Substring to learn how to get a part of provided string by specifying the start index and end index to the substring function.

* will not be published
* hint: http://www.example.com