The indexOf () method returns the position of the first occurrence of a specified string value. Syntax
StringObject. indexOf (searchvalue, fromindex)
Parameter description
Searchvalue is required. Specifies the string value to be retrieved.
Fromindex integer. Specifies the position where the search starts in the string. The valid value is 0 to stringObject. length-1. If this parameter is omitted, it is retrieved from the first character of the string.
Description
This method retrieves the stringObject string from start to end to see if it contains the searchvalue. The start position is at the string's fromindex or the start of the string (when fromindex is not specified ). If a searchvalue is found, the first position of the searchvalue is returned. The character position in stringObject starts from 0.
Tips and comments
Note: The indexOf () method is case sensitive!
Note: If the string value to be retrieved does not appear, this method returns-1.
Instance:
Var src = "images/off_1.png"; alert (src. indexOf ('t'); alert (src. indexOf ('I'); alert (src. indexOf ('g '));
// The pop-up values are:-1, 0, and 3.