How do you check if a string contains a specific substring in modern JavaScript?
Use the ES6 **String.prototype.includes()** method, which returns trueorfalsedirectly and is much cleaner than checkingindexOf() !== -1`.
Using .includes() (Recommended)
const title = "Welcome to A1Lab Forum";
if (title.includes("A1Lab")) {
console.log("Substring found!");
}
Case-Insensitive Substring Check
Normalize case first: Convert both strings with .toLowerCase() before calling .includes().
const exists = title.toLowerCase().includes("a1lab"); // true'
You must log in or register to comment.
