Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

JavaScript | Intl.getCanonicalLocales() Method

  • Last Updated : 16 Apr, 2020

The Intl.getCanonicalLocales() method in JavaScript is a Standard built-in objects which returns an array containing the canonical locale names.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

Intl.getCanonicalLocales(locales)

Parameters: This method accepts 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:




console.log(Intl.getCanonicalLocales('EN-US'));
console.log(Intl.getCanonicalLocales(['EN-US', 'Fr']));
  
try {
    Intl.getCanonicalLocales('GeeksforGeeks');
} catch (error) {
    console.log(error);
}

Output:

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

Example 2:




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);
}

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
  • Firefox
  • Opera
  • Safari
  • Edge
My Personal Notes arrow_drop_up
Recommended Articles
Page :