JavaScript(JS) JS check whether a string contains a substring

To check whether a string contains a substring in JavaScript/JS, you can use the includes() method, which returns a boolean value indicating whether a string contains a specified substring. Here's an example:

ref‮gi:ot re‬iftidea.com
const myString = "Hello, world!";
const substring = "world";

if (myString.includes(substring)) {
  console.log("The string contains the substring.");
} else {
  console.log("The string does not contain the substring.");
}

In this example, we have a string myString and a substring substring. We use the includes() method to check if the string contains the substring. Since the substring "world" is present in the string "Hello, world!", the includes() method will return true.