JavaScript (ES2026) reference · String Methods
JavaScript String includes() Method
Return true if the string contains the given text anywhere. Case-sensitive.
JavaScript (ES2026) Since ES2015
Syntax
string.includes(searchString, position)
Parameters
| Parameter | Description |
|---|---|
searchString |
Text to look for. |
position optional |
Index to start searching from. Default: 0 |
Return value
true or false.
Examples
const msg = "Payment failed: card declined";
console.log(msg.includes("failed"), msg.includes("Failed"));
Output
true false
const q = "JAVA";
console.log("JavaScript".toLowerCase().includes(q.toLowerCase()));
Output
true
Version history
| Version | Change |
|---|---|
| JavaScript ES2015 | Added |
In other languages
str_contains()· PHP
Related
string.indexOf()· Return the index of the first occurrence of some text, or -1 if it isn't found.string.startsWith()· Return true if the string begins with the given text. Case-sensitive; an optional position starts the check later.string.search()· Return the index of the first regular-expression match, or -1 if there is none.array.includes()· Return true if the array contains a value, using SameValueZero equality (so it finds NaN, unlike indexOf).- JavaScript Strings · tutorial
- JavaScript String Methods · tutorial