The includes(string, index) method

The includes() method is used to find whether one string may be found in another string, returning true or false as appropriate. Here is an example to demonstrate this:

const str = "Hi, I am a JS Developer";console.log(str.includes("JS")); //Output "true"

It takes an optional second parameter representing the position in the string at which to begin searching. Here is an example to demonstrate this:

const str = "Hi, I am a JS Developer";console.log(str.includes("JS", 13)); // Output "false"

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.