Open In App

What is includes() Method in JavaScript ?

In JavaScript, the includes() method is used to determine whether a string contains another string or a specified value. It returns true if the string contains the specified value, and false otherwise.

Syntax:

string.includes(searchValue, startIndex)

Example: Here, the includes() method is called on the str string to determine whether it contains the substring “World”. Since “World” is present within the string, the method returns true, which is then assigned to the variable containsWorld.




const str = "Hello, World!";
const containsWorld = str.includes("World");
 
console.log(containsWorld); // Output: true

Output
true

Article Tags :