Skip to content
Related Articles

Related Articles

JavaScript | Intl.getCanonicalLocales() Method

Improve Article
Save Article
Like Article
  • Last Updated : 20 Nov, 2021

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

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: 
 

javascript




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: 
 

javascript




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 54 and above
  • Firefox 48 and above
  • Safari 11 and above
  • Edge 16 and above

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!