Javascript indexof
Returns the position of the substring that appears for the first time in the string object.
Javascript indexof format
Strobj. indexof (substring, start)
The strobj parameter is required. String object or text.
Substring is required. The substring to be searched by the indexof function in the string object.
Start is optional. This integer indicates the index in the string object. If it is omitted, It is searched from the first character of the string.
Note:
The indexof method returns an integer indicating the starting position of the substring in the string object. If no substring is found,-1 is returned. Javascript indexof functions are case sensitive.
CodeExample:
1 < Script Type = " Text/JavaScript " >
2 VaR Str1 = " Javascript indexof " ;
3 VaR S = Str1.indexof ( " Javascript " );
4 VaR S1 = Str1.indexof ( " Indexof " );
5 VaR S2 = Str1.indexof ( " Indexof " );
6 Document. Write ( " The position of Javascript in the string JavaScript indexof is <font color = Red> " );
7 Document. Write (s );
8 Document. Write ( " </Font> bit <br> " );
9
10 Document. Write ( " The position of indexof in the string JavaScript indexof is <font color = Red> " );
11 Document. Write (S1 );
12 Document. Write ( " </Font> bit <br> " );
13
14 Document. Write ( " The position of indexof in the string JavaScript indexof is <font color = Red> " );
15 Document. Write (S2 );
16 Document. Write ( " </Font> bit <br> " );
17 < / SCRIPT>