String.lastIndexOf

Returns the index within the calling String object of the last occurrence of the specified value, or -1 if not found. The calling string is searched backward, starting at fromIndex.

Method of String

Syntax

lastIndexOf( searchValue[, fromIndex] )

Parameters

Parameter Description
searchValue A string representing the value to search for.
fromIndex The location within the calling string to start the search from. It can be any integer between 0 and the length of the string. The default value is the length of the string.

Description

Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character is stringName.length - 1.

The lastIndexOf method is case sensitive. For example, the following expression returns -1:

See also

String.charAt, String.indexOf, String.split

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.