Check a String Sontains a Substring in JavaScript? [Two Methods]
To check if a string contains a specific substring in JavaScript, you can use the includes() method or the indexOf() method. Here’s how you can use each method: Using includes() method: var str = “Hello, World!”; var substring = “Hello”; if (str.includes(substring)) { console.log(“Substring found!”); } else { console.log(“Substring not found.”); } In this example, … Read more