可以使用 JavaScript 中的 includes() 方法来判断字符串中是否包含另一个字符串。例如:

let str = "Hello, World!";
let target = "World";

if (str.includes(target)) {
  console.log(`"${target}" was found in "${str}"`);
} else {
  console.log(`"${target}" was not found in "${str}"`);
}

输出结果为:

"World" was found in "Hello, World!"
如何用js判断字符串是否包含某个字符串

原文地址: http://www.cveoy.top/t/topic/Nyf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录