Intl.NumberFormat.supportedLocalesOf()
Intl.NumberFormat.supportedLocalesOf() 靜態方法返回一個數組,其中包含提供的 locale 中在不回退到執行時預設 locale 的情況下,受數字格式化支援的 locale。
試一試
const locales = ["ban", "id-u-co-pinyin", "de-ID"];
const options = { localeMatcher: "lookup" };
console.log(Intl.NumberFormat.supportedLocalesOf(locales, options));
// Expected output: Array ["id-u-co-pinyin", "de-ID"]
// (Note: the exact output may be browser-dependent)
語法
js
Intl.NumberFormat.supportedLocalesOf(locales)
Intl.NumberFormat.supportedLocalesOf(locales, options)
引數
locales-
一個帶有 BCP 47 語言標籤的字串,或者此類字串的陣列。關於
locales引數的一般形式和解釋,請參閱Intl主頁上的引數說明。 options可選-
一個可能具有以下屬性的物件
localeMatcher-
要使用的 locale 匹配演算法。可能的值為
"lookup"和"best fit";預設值為"best fit"。有關此選項的資訊,請參閱 Intl 頁面。
返回值
一個字串陣列,表示在不回退到執行時預設 locale 的情況下,受數字格式化支援的給定 locale 標籤的子集。
示例
使用 supportedLocalesOf()
假設一個執行時支援印尼語和德語的數字格式化,但不支援巴釐語,supportedLocalesOf 會原樣返回印尼語和德語語言標籤,即使 pinyin 排序與數字格式化無關也未用於印尼語,並且不太可能支援印尼語的特殊德語。請注意此處指定了 "lookup" 演算法 — "best fit" 匹配器可能會認為印尼語足以匹配巴釐語,因為大多數巴釐語使用者也懂印尼語,因此也會返回巴釐語語言標籤。
js
const locales = ["ban", "id-u-co-pinyin", "de-ID"];
const options = { localeMatcher: "lookup" };
console.log(Intl.NumberFormat.supportedLocalesOf(locales, options));
// ["id-u-co-pinyin", "de-ID"]
規範
| 規範 |
|---|
| ECMAScript® 2026 國際化 API 規範 # sec-intl.numberformat.supportedlocalesof |
瀏覽器相容性
載入中…