IMLC.ME

JavaScript 如何检查字符串是否包含特定字符

ECMAScript 6

String.prototype.includes()

console.log("Hello, world!".includes("world")); // true

IE 浏览器或者 ECMAScript 5 以及之前的版本

String.prototype.indexOf()

console.log("Hello, world!".indexOf("world") !== -1); // true