Array.prototype.toLocaleString()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since â¨2015ë 7ìâ©.
toLocaleString() ë©ìëë Array ì¸ì¤í´ì¤ì ë°°ì´ì ìì를 ëíë´ë
문ìì´ì ë°íí©ëë¤.
ê° ììë ìì²´ toLocaleString ë©ìë를 ì¬ì©íì¬ ë¬¸ìì´ë¡ ë³íëë©°, ì´ë¬í 문ìì´ì ì¼í(",")ì ê°ì ë¡ì¼ì¼ë³ êµ¬ë¶ ë¬¸ìì´ë¡
ë¶ë¦¬ë©ëë¤.
ìëí´ ë³´ê¸°
const array1 = [1, "a", new Date("21 Dec 1997 14:12:00 UTC")];
const localeString = array1.toLocaleString("en", { timeZone: "UTC" });
console.log(localeString);
// ìì ê²°ê³¼ ê°: "1,a,12/21/1997, 2:12:00 PM",
// ì´ê²ì "en" ë¡ì¼ì¼ê³¼ UTC ìê°ë를 기ë°ì¼ë¡ í©ëë¤. ë°ë¼ì ê²°ê³¼ ê°ì´ ë¤ë¥¼ ì ììµëë¤.
구문
toLocaleString()
toLocaleString(locales)
toLocaleString(locales, options)
매ê°ë³ì
localesOptional-
BCP 47 ì¸ì´ í그를 í¬í¨íë 문ìì´ ëë 문ìì´ ë°°ì´.
localesì¸ìì ì¼ë°ì ì¸ íìê³¼ í´ìì ëí ë´ì©ìIntl매ê°ë³ì ì¤ëª ë©ì¸ íì´ì§ìì íì¸íì¸ì. optionsOptional-
êµ¬ì± ìì±ì í¬í¨íë ê°ì²´. ì¬ê¸°ìì ì ë¬í ì ìë ê°ì ë³íëë ììì ë°ë¼ ë¤ë¦ ëë¤. ì를 ë¤ì´, ì«ìì ê²½ì°
Number.prototype.toLocaleString()를 ì°¸ê³ íì¸ì.
ë°í ê°
ë°°ì´ì ìì를 íííë 문ìì´.
ì¤ëª
Array.prototype.toLocaleString ë©ìëë ì ê³µë locales ë° options 매ê°ë³ì를 ì¬ì©íì¬ ê° ìììì toLocaleString ë©ìë를 í¸ì¶íë©´ì ìì를 ìíí©ëë¤. ê·¸ë¦¬ê³ ì¼íì ê°ì 구íì ë°ë¼ ì ìë êµ¬ë¶ ë¬¸ì를 ì¬ì©íì¬ ë°íë 문ìì´ì ì°ê²°í©ëë¤. ì´ ë©ìëë ë ê°ì 매ê°ë³ì를 ì§ì ì¬ì©íì§ ìì¼ë©°, ë¨ìí ê° ììì toLocaleString() ë©ìëë¡ ì ë¬í©ëë¤. êµ¬ë¶ ë¬¸ìì´ì ì íì locales 매ê°ë³ìê° ìë í¸ì¤í¸ì íì¬ ë¡ì¼ì¼ì ë°ë¼ ê²°ì ë©ëë¤.
ììê° undefined, nullì´ë©´, "null"ì´ë "undefined" ëì ë¹ ë¬¸ìì´ë¡ ë³íë©ëë¤.
í¬ì ë°°ì´ìì toLocaleString() ë©ìëë ë¹ ì¬ë¡¯ì undefined ê°ì ê°ì§ê³ ìë ê²ì²ë¼ ì²ë¦¬íë©° ë°ë³µí©ëë¤.
toLocaleString() ë©ìëë ì ë¤ë¦ì
ëë¤. this ê°ì´ length ìì±ê³¼ ì ì í¤ ìì를 ê°ì§ê³ ìì¼ë©´ ì¬ì©í ì ììµëë¤.
ìì
>ë¡ì¼ì¼ê³¼ ìì± ì¬ì©
ë°°ì´ì ììë toLocaleString ë©ìë를 ì¬ì©íì¬ ë¬¸ìì´ë¡ ë³íë©ëë¤. ì를 ë¤ì´, ì´ ì½ëììë prices ë°°ì´ì 문ìì´ê³¼ ì«ìì ëí´ ìëì¼ë¡ Number.prototype.toLocaleString() ë©ìë를 í¸ì¶íì¬ íµí íìì¼ë¡ íìí©ëë¤.
const prices = ["ï¿¥7", 500, 8123, 12];
prices.toLocaleString("ja-JP", { style: "currency", currency: "JPY" });
// "ï¿¥7,ï¿¥500,ï¿¥8,123,ï¿¥12"
í¬ì ë°°ì´ìì toLocaleString() ì¬ì©
toLocaleString()ì ë¹ ì¬ë¡¯ì undefinedì ëì¼íê² ì²ë¦¬íë©° ì¶ê°ì ì¸ êµ¬ë¶ ë¬¸ì를 ìì±í©ëë¤.
console.log([1, , 3].toLocaleString()); // '1,,3'
ë°°ì´ì´ ìë ê°ì²´ìì toLocaleString() ì¬ì©
toLocaleString() ë©ìëë thisì length ìì±ì íì¸íê³ lengthë³´ë¤ ìì ììê° ìë ì ì를 í¤ë¡ ê°ì§ ìì±ì ì ê·¼í©ëë¤.
const arrayLike = {
length: 3,
0: 1,
1: 2,
2: 3,
3: 4, // lengthê° 3ì´ë¯ë¡ toLocaleString()ì ìí´ ë¬´ìë©ëë¤
};
console.log(Array.prototype.toLocaleString.call(arrayLike));
// 1,2,3
ëª ì¸ì
| Specification |
|---|
| ECMAScript® 2026 Language Specification > # sec-array.prototype.tolocalestring > |
| ECMAScript® 2026 Internationalization API Specification > # sup-array.prototype.tolocalestring > |