How to Check if a String Contains a Substring in JavaScript
In this lesson, we will see how to check if a string contains a substring in JavaScript, sometimes we want to check if a given string contains a specified substring so how we can do that?
The includes() method
To do that we can use the includes() method that returns true if a string contains a substring if not it returns false.
const sayHello = 'Hello World';
console.log(sayHello.includes('World'));
// true