Saturday, July 19, 2025
HomeLanguagesJavascriptJavaScript Intl.getCanonicalLocales() Method

JavaScript Intl.getCanonicalLocales() Method

The Intl.getCanonicalLocales() method in JavaScript is a Standard built-in object which returns an array containing the canonical locale names. Elements will be checked for structural validity and duplicates will be removed.

Syntax: 

Intl.getCanonicalLocales(locales)

Parameters: This method accepts a single parameter as mentioned above and described below: 

  • locales: This parameter holds a list of string values for which to get the canonical locale names.

Return value: This method returns an array containing the canonical locale names.

Below examples illustrate the Intl.getCanonicalLocales() method in JavaScript:

Example 1: This example shiows the use of the Intl.getCanonicalLocales() method in JavaScript.

javascript




<script>
    console.log(Intl.getCanonicalLocales('EN-US'));
    console.log(Intl.getCanonicalLocales(['EN-US', 'Fr']));
      
    try {
        Intl.getCanonicalLocales('neveropen');
    } catch (error) {
        console.log(error);
    }
</script>


Output: 

Array ["en-US"]
Array ["en-US", "fr"]
RangeError: Incorrect locale information provided

Example 2: This example shiows the use of the Intl.getCanonicalLocales() method in JavaScript.

javascript




<script>
    console.log(Intl.getCanonicalLocales('EN-US'));
    console.log(Intl.getCanonicalLocales(['EN-US', 'Fr']));
      
    try {
        console.log(Intl.getCanonicalLocales(['Tr', 'UT']));
    } catch (error) {
        console.log(error);
    }
</script>


Output: 

Array ["en-US"]
Array ["en-US", "fr"]
Array ["tr", "ut"]

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

  • Google Chrome 54 and above
  • Firefox 48 and above
  • Safari 11 and above
  • Edge 16 and above
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32154 POSTS0 COMMENTS
Milvus
67 POSTS0 COMMENTS
Nango Kala
6529 POSTS0 COMMENTS
Nicole Veronica
11677 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11737 POSTS0 COMMENTS
Shaida Kate Naidoo
6623 POSTS0 COMMENTS
Ted Musemwa
6899 POSTS0 COMMENTS
Thapelo Manthata
6590 POSTS0 COMMENTS
Umr Jansen
6583 POSTS0 COMMENTS