While this tutorial has content that we believe is of great benefit to our community, we have not yet tested or edited it to ensure you have an error-free learning experience. It's on our list, and we're working on it! You can help us out by using the "report an issue" button at the bottom of the tutorial.
Use the includes() method to search for a substring inside a string:
var word = "bravery"; console.log(word.includes(“rave”)); // true
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:
Remember that the comparison takes cases into consideration:
var greetings = “Hi Sammy ~”; console.log(greetings.includes(“hi”)); // false