2025年01月25日 建站教程
indexOf()方法可返回某个指定的字符串值在字符串中首次出现的位置。下面web建站小编给大家详细介绍一下indexOf()方法的具体运用!
基本语法:
stringObject.indexOf(searchvalue,fromindex)
参数介绍:
| 参数名 | 描述 | 
|---|---|
| searchvalue | 必需。规定需检索的字符串值。 | 
| fromindex | 可选的整数参数。规定在字符串中开始检索的位置。 它的合法取值是 0 到 stringObject.length – 1。  | 
示列如下:
var str="Hello world!"
console.log(str.indexOf("Hello")) //0
console.log(str.indexOf("World")) //-1
console.log(str.indexOf("world")) //6
			
                                        本文链接:http://so.lmcjl.com/news/22020/