目录

String.prototype.includes(searchString, position = 0)

该方法确定字符串是否是给定字符串的子字符串。

语法 (Syntax)

str.includes(searchString[, position])

参数 (Parameters)

  • searchString - 要搜索的子字符串。

  • Position - 此字符串中开始搜索searchString的位置; 默认为0。

返回值 (Return Value)

如果字符串包含子字符串,则为true ; 否则,是的。

例子 (Example)

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))

输出 (Output)

false 
true 
true 
true 
↑回到顶部↑
WIKI教程 @2018