Open In App

JavaScript Intl Collator supportedLocalesOf() Method

Last Updated : 24 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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: 

  • locales: This parameter is a string with a BCP 47 language tag or an array of such strings.
  • options: It is an optional parameter. It is an object that has localeMatcher property. The localeMatcher is the locale-matching algorithm to use. It has the values “lookup” and “best fit”.

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.

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.

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: 

  • Google Chrome 24 and above
  • Firefox 29 and above
  • Opera 15 and above
  • Edge 12 and above
  • IE 11 and above
  • Safari 10 and above

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads