- 'J' is at index no.0
- 'a' is at index no.1
- 'v' is at index no.2
- and so on
Similarly the first character of "Fun", that is 'F' is at index no.14, therefore the output of the above program is 14.
The startIndex parameter is optional. Its default value is 0. This parameter is used when we need to start searching for specified subString from any particular startIndex value. For example:
Since the searching for "is" starts from 15th index, therefore the first "is" has skipped.
Note - The indexOf() method returns the index of first character of specified value. Otherwise returns -1 in case if specified value does not exists in the specified string.
« Previous Tutorial Next Tutorial »
Like/Share Us on Facebook 😋