indexOf Examples
The general syntax for this method is:
stringName.indexOf(substr);
Given a candidate substring, this method returns the integer index of the first occurrence of the substring in the string. If the substring does not occur in the string, -1 is returned.
Example
|
|
Console Output
6
-1
0
Example
An email address must contain an @
symbol. Checking for the presence of this symbol is a part of email address verification in most programs.
|
|
Console Output
Email contains @