當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


JavaScript Intl.Collator.supportedLocalesOf()用法及代碼示例

Intl.Collat​​or.supportedLocalesOf()方法是JavaScript中的內置方法,用於返回一個數組,其中包含排序規則中支持的所提供語言環境的數組,而不必回退到運行時的默認語言環境。

用法:

Intl.Collator.supportedLocalesOf(locales, options)

參數:此方法接受上麵提到並在下麵描述的兩個參數:

  • locales:此參數是帶有BCP 47語言標記的字符串,或此類字符串的數組。
  • options:它是一個可選參數。它是一個具有localeMatcher屬性的對象。 localeMatcher是要使用的語言環境匹配算法。它的值為“lookup”和“best fit”。

返回值:此方法返回一個字符串數組,該字符串表示給定的區域設置標簽的子集。

以下示例說明了JavaScript中的Intl.Collat​​or.supportedLocalesOf()方法:



範例1:

const locales1 = ['ban', 'id-u-co-pinyin', 'de-ID']; 
console.log(Intl.Collator.supportedLocalesOf(locales1));

輸出:

Array ["id-u-co-pinyin", "de-ID"]

範例2:

const locales1 = ['ban', 'id-u-co-pinyin', 'de-ID']; 
const options1 = { localeMatcher:'lookup' }; 
let val = Intl.Collator.supportedLocalesOf(locales1, options1) 
console.log(val[0]); 
console.log(val[1]);

輸出:

"id-u-co-pinyin"
"de-ID"

支持的瀏覽器:下麵列出了由Intl.Collat​​or.supportedLocalesOf()方法支持的瀏覽器:

  • 穀歌瀏覽器
  • Firefox
  • Opera
  • Edge
  • IE
  • Safari

相關用法


注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 JavaScript | Intl.Collator.supportedLocalesOf() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。