Use the includes() method to search for a substring inside a string:
var word = "bravery"; console.log(word.includes(“rave”)); // true
— Sorry to interrupt this program! 📺
Given the current situation with COVID-19, times are hard for most of us, but if you're stuck at home you can perhaps use that extra time to work on your front-end skills. Wes put all of his courses at 50% off to help out with the current challenge we're facing.
Plus, these are affiliate links, so if you purchase a course you help Alligator.io continue to exist at the same time! 🙏
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 burnIntro = “Yo momma ~”; console.log(burnIntro.includes(“yo”)); // false