// 使用 includes 方法检查字符串中是否包含指定的子字符串
const str = "Hello, world!";
const substr = "world";
if (str.includes(substr)) {
console.log("字符串中包含 'world'");
} else {
console.log("字符串中不包含 'world'");
}
// includes 方法返回一个布尔值,表示指定的子字符串是否存在。
// 它区分大小写,因此 "World" 和 "world" 被认为是不同的字符串。
// 示例:检查大小写敏感性
console.log(str.includes("World")); // false
console.log(str.includes("world")); // true
上一篇:js 整数正则
下一篇:js string转float
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站