[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/includes [Back]  [Original]

String.prototype.includes() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

String.prototype.includes()

20159

String includes() true false

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"

js
includes(searchString)
includes(searchString, position)

searchString

str undefinedincludes() "undefined"

position

searchString 0

searchString true false

TypeError

searchString

includes() false

js
"Blue Whale".includes("blue"); //  false

js
"Blue Whale".toLowerCase().includes("blue"); //  true

includes()

js
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

ECMAScript 2027 LanguageSpecification
# sec-string.prototype.includes


Web Proxy Viewer  |  New URL  |  Original Page