| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/fa/docs/Web/JavaScript/Reference/Global_Objects/String/includes | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since September 2015.
The includes() method of String values performs a case-sensitive search to determine whether a given string may be found within this string, returning true or false as appropriate.
const sentence = "The quick brown fox jumps over the lazy dog.";
const word = "fox";
console.log(
`The word "${word}" ${
sentence.includes(word) ? "is" : "is not"
} in the sentence`,
);
// Expected output: "The word "fox" is in the sentence"
includes(searchString)
includes(searchString, position)
searchStringA string to be searched for within str. Cannot be a regex. All values that are not regexes are coerced to strings, so omitting it or passing undefined causes includes() to search for the string "undefined", which is rarely what you want.
position OptionalThe position within the string at which to begin searching for searchString. (Defaults to 0.)
true if the search string is found anywhere within the given string, including when searchString is an empty string; otherwise, false.
TypeErrorThrown if searchString is a regex.
This method lets you determine whether or not a string includes another string.
The includes() method is case sensitive. For example, the following expression returns false:
"Blue Whale".includes("blue"); // returns false
You can work around this constraint by transforming both the original string and the search string to all lowercase:
"Blue Whale".toLowerCase().includes("blue"); // returns true
const str = "To be, or not to be, that is the question.";
console.log(str.includes("To be")); // true
console.log(str.includes("question")); // true
console.log(str.includes("nonexistent")); // false
console.log(str.includes("To be", 1)); // false
console.log(str.includes("TO BE")); // false
console.log(str.includes("")); // true
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-string.prototype.includes |
String.prototype.includes in core-jsString.prototype.includesArray.prototype.includes()TypedArray.prototype.includes()String.prototype.indexOf()String.prototype.lastIndexOf()String.prototype.startsWith()String.prototype.endsWith()This page was last modified on Jul 10, 2025 by MDN contributors.
Stringanchor()at()big()blink()bold()charAt()charCodeAt()codePointAt()concat()endsWith()fixed()fontcolor()fontsize()includes()indexOf()isWellFormed()italics()lastIndexOf()link()localeCompare()match()matchAll()normalize()padEnd()padStart()repeat()replace()replaceAll()search()slice()small()split()startsWith()strike()sub()substr()substring()sup()toLocaleLowerCase()toLocaleUpperCase()toLowerCase()toString()toUpperCase()toWellFormed()trim()trimEnd()trimStart()valueOf()[Symbol.iterator]()Object/FunctionYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |