本文共 569 字,大约阅读时间需要 1 分钟。
字符串indexof方法
Gives the position of the first occurrence of the string passed as parameter in the current string. Returns -1 if the string is not found.
给出作为参数传递的当前字符串中字符串首次出现的位置。 如果找不到该字符串,则返回-1。
'JavaScript'.indexOf('Script') //4'JavaScript'.indexOf('JavaScript') //0'JavaScript'.indexOf('aSc') //3'JavaScript'.indexOf('C++') //-1
You can pass a second parameters to set the starting point:
您可以传递第二个参数来设置起点:
'a nice string'.indexOf('nice') !== -1 //true'a nice string'.indexOf('nice', 3) !== -1 //false'a nice string'.indexOf('nice', 2) !== -1 //true
翻译自:
字符串indexof方法
转载地址:http://vaqgb.baihongyu.com/