Function-indexOf() ╰半橙微兮° 2022-03-30 17:28 217阅读 0赞 ## 定义和用法 ## *string*.indexOf(*searchvalue*,*start*) indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置,number类型。 如果没有找到匹配的字符串则返回 -1。 **注意:** indexOf() 方法区分大小写。 **提示:** 同样你可以查看类似方法 [lastIndexOf()][lastIndexOf] 。 ## 参数值 ## <table> <tbody> <tr> <th>参数</th> <th>描述</th> </tr> <tr> <td><em>searchvalue</em></td> <td>必需。规定需检索的字符串值。</td> </tr> <tr> <td><em>start</em></td> <td>可选的整数参数。规定在字符串中开始检索的位置。它的合法取值是 0 到 string Object.length - 1。如省略该参数,则将从字符串的首字符开始检索。</td> </tr> </tbody> </table> ## 实例 ## 查找字符串 "welcome": var str="Hello world, welcome to the universe."; var n=str.indexOf("welcome"); *n* 输出结果: 13 [lastIndexOf]: http://www.runoob.com/jsref/jsref-lastindexof.html
还没有评论,来说两句吧...