JavaScript indexOf method
The indexOf method is used to calculate the first occurrence position of a specified string in the string and return the value. Its syntax is as follows:
Parameter description:
参数 | 说明 |
---|---|
str_object | 要操作的字符串(对象) |
search | 必需。要检索的字符串 |
start | 可选。指定开始检索的位置,如省略该参数,则将从字符串的首字符开始检索 |
Tip: String counting starts from 0.
indexOf method instance
Run this example, output:
indexOf is case-sensitive, if the string value to be retrieved does not appear, the method returns -1.