日常开发记录-indexOf方法

indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。

如果没有找到匹配的字符串则返回 -1。
let str = "hello world , welcome."
console.log(str.indexOf("he"))  // 0
console.log(str.indexOf("xxxx")) // -1
 

 

 

posted on 2022-06-18 22:41  法老的微笑  阅读(21)  评论(0)    收藏  举报