indexOf()  String  instance method getterS2C Home
      « Globals « String « indexOf()
Description
Returns the index value for the first occurence of the specified string from the specified starting index.
- Returns -1 if the specified string value is not found.
Syntax
| Signature | Description | 
|---|---|
| aString.indexOf(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 the length of the string. | 
Examples
The code below creates a string of the alphabet and returns starting index for specified string value.
// Create alphabet string varible.
var theAlphabet = 'abcdefghijklmnopqrstuvwxyz';
// Return index of first occurence of search string.
alert(theAlphabet.indexOf('jkl'));
Related Tutorials
JavaScript Basic Tutorials - Lesson 8 - Strings
 
  
  
  
 Homepage
 Homepage Top
 Top