![]() |
VOOZH | about |
The includes() method is used to check whether a string contains a specific value. It returns a boolean result based on whether the text is found or not.
string.includes(searchvalue, start)The includes() method accepts parameters that control how the search is performed. These parameters define what to search for and where to start searching.
The includes() method provides a simple true or false result. This result tells whether the given value exists in the string.
Example 1: The code checks whether "Geeks" exists in "Welcome to GeeksforGeeks." and logs true because the substring is found.
Example 2: Here, the second parameter is not provided, so the search starts from index 0. Since the method is case-sensitive, it treats the strings differently and therefore returns false.
Example 3: The code checks whether the character "o" exists in "Welcome to GeeksforGeeks." starting from index 17 and logs false, since "o" does not appear after that index.
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.