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 | 
浏览器兼容性
加载中…