字符串新增方法
传统上,Javascript只要indexOf方法,可以用来确定一个字符串是否包含在另一个字符串中。ES6又提供了三种新方法。
includes()
返回布尔值,表示是否找到了参数字符串
let a = "Hello world";
a.includes('o') //true
第二个参数:表示开始搜索的位置
console.log(a.includes('o',9)) //false
startsWith()
返回布尔值,表示参数字符串是否在原字符串的头部
let a = 'He
原创
2021-08-24 15:21:26 ·
195 阅读 ·
0 评论