0
ECMAScript6引入了 String.prototype.includes
const string = "foo";
const substring = "oo";
console.log(string.includes(substring));
但是includes 不支持Internet Explorer。在ECMAScript 5或更以前的环境下,可以使用String.prototype.indexOf,当找不到子字符串时,返回-1:
var string = "foo";
var substring = "oo";
console.log(string.indexOf(substring) !== -1);
收藏