Javascript string includes() is an inbuilt function that determines whether one string may be found within another string, returning true or false as appropriate. With ES6 JavaScript added the includes method natively to both the Array and String natives. While true or false may provide the answer you need, regular expressions can check if a substring exists with a more detailed answer.

Javascript String Includes Example

The string includes() method lets you determine whether or not a  string includes another string. See the following syntax.

str.includes(searchString)

It has only one required parameter which is searchString. It is the substring, which we need to search in the String. See the following example.

// app.js

strA = 'Hello World, Welcome to ES9';

console.log(strA.includes('ES9'));

In the above example, we are checking if the ES9 substring is there inside the strA and if yes then it will return true. In the above example, it is there, so we will see the output true.

#javascript #includes* #string.prototype.includes #js

Javascript String Includes Example | String.prototype.includes()
2.00 GEEK