Saturday, August 30, 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
32249 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6617 POSTS0 COMMENTS
Nicole Veronica
11792 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11838 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7013 POSTS0 COMMENTS
Thapelo Manthata
6689 POSTS0 COMMENTS
Umr Jansen
6701 POSTS0 COMMENTS