Determine whether a string contains the specified substring.
The includes() method performs a case-sensitive search to determine whether one string may be found within another string, returning true or false. An optional position argument specifies the index to start searching from.
Unlike indexOf(), which returns the position, includes() returns a boolean, making conditional checks more readable. The search is case-sensitive, so 'Hello'.includes('hello') returns false.
Introduced in ES2015, includes() is the preferred way to check for substring existence in modern JavaScript. For case-insensitive checks, convert both strings to the same case before comparing.
| Name | Description | Optional |
|---|---|---|
searchString |
The substring to search for. | No |
position |
The position within the string to begin searching. Defaults to 0. | Yes |
'Hello World'.includes('World'); // true
'Hello World'.includes('world'); // false