Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

String.prototype.includes()

BaselineWidely available

Theincludes() method ofString values performs a case-sensitive search to determine whether a given string may be found within this string, returningtrue orfalse as appropriate.

Try it

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"

Syntax

js
includes(searchString)includes(searchString, position)

Parameters

searchString

A string to be searched for withinstr. Cannotbe a regex. All values that are not regexes arecoerced to strings, so omitting it or passingundefined causesincludes() to search for the string"undefined", which is rarely what you want.

positionOptional

The position within the string at which to begin searching forsearchString. (Defaults to0.)

Return value

true if the search string is found anywhere within the given string, including whensearchString is an empty string; otherwise,false.

Exceptions

TypeError

Thrown ifsearchStringis a regex.

Description

This method lets you determine whether or not a string includes another string.

Case-sensitivity

Theincludes() method is case sensitive. For example, the following expression returnsfalse:

js
"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:

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

Examples

Using includes()

js
const str = "To be, or not to be, that is the question.";console.log(str.includes("To be")); // trueconsole.log(str.includes("question")); // trueconsole.log(str.includes("nonexistent")); // falseconsole.log(str.includes("To be", 1)); // falseconsole.log(str.includes("TO BE")); // falseconsole.log(str.includes("")); // true

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-string.prototype.includes

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp