lastIndexOf()  String  instance method getterS2C Home
      « Globals « String « lastIndexOf()
Description
Returns the index value for the last occurence of the specified string from the specified starting index.
- Returns -1 if the specified string value is not found.
Syntax
| Signature | Description | 
|---|---|
| aString.lastIndexOf(searchValue[, fromIndex]) | Returns the index value for the first occurence of the specified string from the specified starting index. | 
Parameters
| Parameter | Description | 
|---|---|
| searchValue | A string value. | 
| fromIndex | An integer between 0 and length of the string that defaults to the length of the string. 
 | 
Examples
The code below creates a repeating string and searches backwards through it as both the searchValue and fromIndex parameters are specified.
// Create alphabet string variable.
var repeatingString = 'abcdefabcdefabcdefabcdef';
// Return index of last occurrence of search string.
alert(repeatingString.lastIndexOf('ab', 14));
Related Tutorials
JavaScript Basic Tutorials - Lesson 8 - Strings
 
  
  
  
 Homepage
 Homepage Top
 Top