A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-intl-getcanonicallocales-method/ below:

JavaScript Intl.getCanonicalLocales() Method - GeeksforGeeks

JavaScript Intl.getCanonicalLocales() Method

Last Updated : 27 Dec, 2022

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: 

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('GeeksforGeeks');
    } 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: 



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4