indexOf()方法:返回指定字符串值在字符串中的位置,如果没有找到返回-1,该方法区分大小写。

// 查找字符串 "welcome":
var str="Hello world, welcome to the universe.";
var n=str.indexOf("welcome");//n=13

语法:string.indexOf(searchvalue,start)

//在字符串查找字符 "e" 第一次出现的位置:
var str="Hello world, welcome to the universe.";
var n=str.indexOf("e");//n=1

//在字符串第五个位置开始查找字符 "e" 第一次出现的位置:
var str="Hello world, welcome to the universe.";
var n=str.indexOf("e",5);//n=14
Logo

Vue社区为您提供最前沿的新闻资讯和知识内容

更多推荐