ES6 - 新字符串方法 includes()
该方法确定字符串是否为给定字符串的子字符串。
语法
str.includes(searchString[, position])
参数
searchString − 要搜索的子字符串。
Position − 在此字符串中开始搜索 searchString 的位置;默认为 0。
返回值
如果字符串包含子字符串,则为 true;否则为 false。
示例
var str = 'Hello World'; console.log(str.includes('hell')) console.log(str.includes('Hell')); console.log(str.includes('or')); console.log(str.includes('or',1))
输出
false true true true