String.prototype.endsWith()
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ì.
String ê°ì endsWith() ë©ìëë 문ìì´ì´ ì´ ë¬¸ìì´ì 문ìë¡ ëëëì§ ì¬ë¶ë¥¼ ê²°ì íì¬ ì ì íê² true ëë false를 ë°íí©ëë¤.
ìëí´ ë³´ê¸°
const str1 = "Cats are the best!";
console.log(str1.endsWith("best!"));
// Expected output: true
console.log(str1.endsWith("best", 17));
// Expected output: true
const str2 = "Is this a question?";
console.log(str2.endsWith("question"));
// Expected output: false
구문
endsWith(searchString)
endsWith(searchString, endPosition)
매ê°ë³ì
searchString-
strëìì ê²ìí 문ì. ì ê· ííìì´ ë ì ììµëë¤. ì ê·ìì´ ìë 모ë ê°ì [문ìì´ë¡ ê°ì ë³í]ëë¯ë¡ ì´ë¥¼ ìëµíê±°ëundefined를 ì ë¬íë©´endsWith()ê°"undefined"문ìì´ì ê²ìíê² ëëë°, ì´ë ìíë ê²½ì°ê° ê±°ì ììµëë¤. endPositionOptional-
searchStringì´ ë°ê²¬ë ê²ì¼ë¡ ììëë ë ìì¹(searchStringì ë§ì§ë§ 문ìì ì¸ë±ì¤ì 1ì ëí ê°)ì ëë¤. 기본ê°ìstr.lengthì ëë¤.
ë°í ê°
searchStringì´ ë¹ ë¬¸ìì´ì¸ ê²½ì°ë¥¼ í¬í¨íì¬ ë¬¸ìì´ ëì 주ì´ì§ 문ìê° ìì¼ë©´ **true**를 ë°ííê³ , ê·¸ë ì§ ìì¼ë©´ **false**를 ë°íí©ëë¤.
ìì¸
TypeError-
searchStringê° ì ê· ííìì´ë¼ë©´ ë°ìí©ëë¤.
ì¤ëª
ì´ ë©ìë를 ì¬ì©íë©´ 문ìì´ì´ ë¤ë¥¸ 문ìì´ë¡ ëëëì§ ì¬ë¶ë¥¼ íì¸í ì ììµëë¤. ì´ ë©ìëë ëì문ì를 구ë¶í©ëë¤.
ìì
>endsWith() ì¬ì©í기
const str = "To be, or not to be, that is the question.";
console.log(str.endsWith("question.")); // true
console.log(str.endsWith("to be")); // false
console.log(str.endsWith("to be", 19)); // true
ëª ì¸ì
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-string.prototype.endswith> |