js see if text contain hello word
To see if a string contains the word "hello" in JavaScript, you can use the includes() method. Here's an example:
let str = "Hello, world!";
if (str.includes("hello")) {
console.log("The string contains 'hello'");
} else {
console.log("The string does not contain 'hello'");
}
This will output "The string contains 'hello'" because the includes() method is case-sensitive and the string contains the word "Hello". If you want to make it case-insensitive, you can convert the string to lowercase or uppercase using the toLowerCase() or toUpperCase() method before checking for the presence of "hello".
原文地址: https://www.cveoy.top/t/topic/006 著作权归作者所有。请勿转载和采集!