String.prototype.includes()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015ë 9ì.
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"
구문
includes(searchString)
includes(searchString, position)
매ê°ë³ì
searchString-
ì´ ë¬¸ìì´ìì ì°¾ì ë¤ë¥¸ 문ìì´. ì ê·ííìì´ ì¬ ì ììµëë¤.
positionOptional-
searchStringì 찾기 ììí ìì¹. (기본ê°0).
ë°íê°
문ìì´ì ì°¾ìë´ë©´ true . ì¤í¨íë©´ false .
ìì¸
TypeError-
searchStringì´ ì ê·ìì¼ ê²½ì°.
ì¤ëª
ì´ ë©ìë를 ì¬ì©í´ 문ìì´ ë´ì ì°¾ê³ ì íë ë¤ë¥¸ 문ìì´ì´ ìëì§ íì¸í ì ììµëë¤.
ëì문ì 구ë¶
includes() ë©ìëë ëì문ì를 구ë³í©ëë¤. ì를 ë¤ì´ ìë ì½ëë false를 ë°íí©ëë¤.
"Blue Whale".includes("blue"); // returns false
ìëì ê°ì´ ì본 문ìì´ê³¼ ê²ì 문ìì´ì 모ë ì문ìë¡ ë³ííì¬ ì´ ì ì½ ì¡°ê±´ì í´ê²°í ì ììµëë¤.
"Blue Whale".toLowerCase().includes("blue"); // returns true
ìì
>includes() ì¬ì©í기
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 Language Specification> # sec-string.prototype.includes> |