Intl.getCanonicalLocales()
Intl.getCanonicalLocales() 靜態方法返回一個包含規範化區域設定名稱的陣列。重複項將被省略,並且元素將作為結構有效的語言標籤進行驗證。
試一試
console.log(Intl.getCanonicalLocales("EN-US"));
// Expected output: Array ["en-US"]
console.log(Intl.getCanonicalLocales(["EN-US", "Fr"]));
// Expected output: Array ["en-US", "fr"]
try {
Intl.getCanonicalLocales("EN_US");
} catch (err) {
console.log(err.toString());
// Expected output: RangeError: invalid language tag: "EN_US"
}
語法
js
Intl.getCanonicalLocales(locales)
引數
返回值
包含規範化區域設定名稱的陣列。
示例
使用 getCanonicalLocales
js
Intl.getCanonicalLocales("EN-US"); // ["en-US"]
Intl.getCanonicalLocales(["EN-US", "Fr"]); // ["en-US", "fr"]
Intl.getCanonicalLocales("EN_US");
// RangeError: invalid language tag: "EN_US"
規範
| 規範 |
|---|
| ECMAScript® 2026 國際化 API 規範 # sec-intl.getcanonicallocales |
瀏覽器相容性
載入中…