let str = "hellokitty"
// 找到,返回第一个的索引,没取到,返回-1
let aa = str.search("l") // 2
// 找到,返回true,没取到返回false
let bb = str.includes("l") // true
// 找到,返回第一个的索引,没取到,返回-1
let cc = str.indexOf("t") // 7
//(从后面开始找)找到,返回索引,没取到,返回-1
let dd = str.lastIndexOf("l") // 3
Several methods of js judging that a string contains a certain string
Guess you like
Origin blog.csdn.net/qq_32184753/article/details/125656209
Recommended
Ranking