includes() String Method in JavaScript

Use the includes() method to search for a substring inside a string:

var word = "bravery";

console.log(word.includes(“rave”));

// true

Syntax

This quick and easy way to check if one string contains another is very simple to implement. Just call the method with the substring you’re looking for as the argument:

myString.includes(subString);

Case-Sensitive

Remember that the comparison takes cases into consideration:

var burnIntro = “Yo momma ~”;

console.log(burnIntro.includes(“yo”));

// false

Search

🔎 Searching...