Last Updated : 11 Jul, 2025
The includes() method returns true if a string contains a specified string. Otherwise, it returns false.
Syntax:Note: The includes() method is case sensitive i.e. it will treat the Uppercase Characters and Lowercase Characters differently.
string.includes(searchvalue, start)Parameters:
Returns either a Boolean true indicating the presence or it returns a false indicating the absence.
Example 1: The code checks if the string "Geeks" is present in the string "Welcome to GeeksforGeeks.". It then logs the result, which is true
, since "Geeks" is indeed present in the string.
let str = "Welcome to GeeksforGeeks.";
let check = str.includes("Geeks");
console.log(check);
Example 2: Here, the second parameter is not defined, so the search will take place from the starting index. But as this method is case sensitive it will treat the two strings differently, hence returning a boolean false.
javascript
let str = "Welcome to GeeksforGeeks.";
let check = str.includes("geeks");
console.log(check);
Example 3: The code checks if the character "o" is present in the string "Welcome to GeeksforGeeks." starting from index 17. It then logs the result, which is false
, since "o" is not present in the substring starting from index 17.
let str = "Welcome to GeeksforGeeks.";
let check = str.includes("o", 17);
console.log(check);
Example 4: If the computed index (starting index) i.e. the position from which the search will begin is less than 0, the entire array will be searched.
javascript
let str = "Welcome to GeeksforGeeks.";
let check = str.includes("o", -2);
console.log(check);
Supported Browsers:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4