Baseline Widely available
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);
// Expected output: "1,a,12/21/1997, 2:12:00 PM",
// This assumes "en" locale and UTC timezone - your results may vary
æ§æ
toLocaleString()
toLocaleString(locales)
toLocaleString(locales, options)
弿°
locales
çç¥å¯
BCP 47 è¨èªã¿ã°ã®æååãããã®é
åã§ããlocales
弿°ã®ä¸è¬çãªå½¢å¼ã¨è§£éã«ã¤ãã¦ã¯ãIntl
ã¡ã¤ã³ãã¼ã¸ã®å¼æ°ã®èª¬æãåç
§ãã¦ãã ããã
options
çç¥å¯
è¨å®ããããã£ã®ãªãã¸ã§ã¯ãã§ããæ°å¤ã«é¢ãã¦ã¯ Number.prototype.toLocaleString()
ããæ¥ä»ã«é¢ãã¦ã¯ Date.prototype.toLocaleString()
ãè¦ã¦ãã ããã
é åã®è¦ç´ ã表ãæååã§ãã
解説Array.prototype.toLocaleString
ã¡ã½ããã¯ããã®å
容ãèµ°æ»ãããã¹ã¦ã®è¦ç´ ã«å¯¾ã㦠toLocaleString
ã¡ã½ãããã弿° locales
㨠options
ãæå®ãã¦å¼ã³åºããå®è£
ã§å®ç¾©ãããåºåãæå (",") ã§ãã®çµæãé£çµãããã®ãè¿ãã¾ãããã®ã¡ã½ããèªèº«ã¯ããã® 2 ã¤ã®å¼æ°ã使ç¨ãããåè¦ç´ ã«å¯¾ãã toLocaleString()
ã®å¼ã³åºãã§æ¸¡ãã ãã§ãããã¨ã«æ³¨æãã¦ãã ãããåºåãæååã®é¸æã¯ãã¹ãã®ç¾å¨ã®ãã±ã¼ã«ã«ä¾åãã locales
弿°ã¯ä½¿ç¨ãã¾ããã
è¦ç´ ã undefined
ãnull
ã®å ´åãæåå "null"
ã¾ã㯠"undefined"
ã®ä»£ããã«ç©ºæååã«å¤æããã¾ãã
çé
åã§ä½¿ç¨ããå ´åãtoLocaleString()
ã¡ã½ããã¯ç©ºã®ã¹ãããã undefined
ã¨ããå¤ããããã®ããã«å復å¦çãã¾ãã
toLocaleString()
ã¡ã½ããã¯æ±ç¨çã§ãããã®ã¡ã½ãã㯠this
å¤ã« length
ããããã£ã¨æ´æ°ãã¼ã®ããããã£ããããã¨ã ããæå¾
ãã¾ãã
é
åã®è¦ç´ ã¯ããã® toLocaleString
ã¡ã½ããã使ç¨ãã¦æååã«å¤æããã¾ãã
Object
: Object.prototype.toLocaleString()
Number
: Number.prototype.toLocaleString()
Date
: Date.prototype.toLocaleString()
prices
é
åå
ã®æååã¨æ°å¤ã®é貨ã常ã«è¡¨ç¤ºãã¾ãã
const prices = ["ï¿¥7", 500, 8123, 12];
prices.toLocaleString("ja-JP", { style: "currency", currency: "JPY" });
// "ï¿¥7,ï¿¥500,ï¿¥8,123,ï¿¥12"
ãã以å¤ã®ä¾ã«ã¤ãã¦ã¯ã Intl.NumberFormat
ã Intl.DateTimeFormat
ã®ãã¼ã¸ãåç
§ãã¦ãã ããã
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
仿§æ¸ ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4