AD · 728×90
Google AdSense / Яндекс.Директ
Google AdSense / Яндекс.Директ
String
String.includes()
Returns true if a string contains a given substring, false otherwise
Source string
Substring to search for
Position to start searching from
(string).includes(searchString, position)
RESULT
— click Run or press Ctrl+Enter —
Parameter Reference
| Parameter | Type | Status | Description |
|---|---|---|---|
| string | string | required | Source string |
| searchString | string | required | Substring to search for |
| position | number | optional | Position to start searching from |
About
includes() returns true if the string contains the specified substring, false otherwise. A more readable alternative to indexOf() !== -1. Case-sensitive. Related: startsWith() checks the beginning, endsWith() checks the end.
Browser Support
Introduced in ES7/ES2016. PHP got str_contains() only in PHP 8.0 (2020). Before ES2016, indexOf() !== -1 was the standard.
Tips & Gotchas
- includes() is case-sensitive — for case-insensitive: str.toLowerCase().includes(sub.toLowerCase())
- use startsWith() and endsWith() for beginning/end — semantically clearer
- includes() does not accept a RegExp — use test() for patterns.