The lastIndexOf method belongs to the string object. This method searches a string for a character or a group of characters from the last character of the string and returns its index. The index values for each character are counted from the first character. The position of the first character in the string is considered to be at index 0. The method returns -1 when the character is not found.
The syntax of the lastIndexOf method is as follows:
The parameter value is the character or a group of characters to search for.
The parameter startIndex is optional. If this parameter is provided, the counting is started from the character whose index value is one more than the value of the startindex. For example, if the startindex is 3, the search will start from the 4th character.
Some examples of using the lastIndexOf method are as follows:
trace(”This is a string”.lastIndexOf(”s”,5)) //output: 3
trace(”This is a string”.lastIndexOf(”str”)) //output: 10
trace(”This is a string”.lastIndexOf(”z”)) //output: -1