Open In App

JavaScript Intl Collator supportedLocalesOf() Method

The Intl.Collator.supportedLocalesOf() method is an inbuilt method in JavaScript that is used to return an array containing those of the provided locales that are supported in collation without having to fall back to the runtime’s default locale.

Syntax: 



Intl.Collator.supportedLocalesOf(locales, options)

Parameters: This method accepts two parameters as mentioned above and described below: 

Return value: This method returns an array of strings representing a subset of the given locale tags.



The below examples illustrate the Intl.Collator.supportedLocalesOf() method in JavaScript:

Example 1: In this example, we will see the use of the Intl.Collator.supportedLocalesOf() method in JavaScript.




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

Output: 

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

Example 2: In this example, we will print the value of the array one by one using the Intl.Collator.supportedLocalesOf() method in JavaScript.




<script>
    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]);
</script>

Output: 

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

We have a complete list of Javascript Intl methods, to check those please go through the Javascript Intl Complete Reference article.

Supported Browsers: The browsers supported by Intl.Collator.supportedLocalesOf() method are listed below: 

Article Tags :