Skip to content
Related Articles

Related Articles

Improve Article

JavaScript | Intl.DateTimeFormat.supportedLocalesOf() Method

  • Last Updated : 16 Apr, 2020
Geek Week

The Intl.DateTimeFormat.supportedLocalesOf() method is an inbuilt method in JavaScript which returns an array containing those of the provided locales that are supported in date and time formatting.

Syntax:

Intl.DateTimeFormat.supportedLocalesOf(locales, options)

Parameters: This method accept two parameters as mentioned above and described below:

  • locales: This parameter holds a string with a BCP 47 language tag, or an array of such strings.
  • options: It is an optional parameter. It is an object that have localeMatcher property. localeMatcher is the locale matching algorithm to use. It has the values are “lookup” and “best fit”.

Return value: This method returns an array of strings representing the subset of the given locale tags that are supported in date and time formatting.

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



Example 1:




<script>
const geeks = ['ban', 'id-u-co-pinyin', 'de-ID'];
const result = { localeMatcher: 'lookup' };
let val = Intl.DateTimeFormat.supportedLocalesOf(geeks, result);
console.log(val[0], val[1]);
</script>

Output:

"id-u-co-pinyin" "de-ID"

Example 2:




<script>
const geeks = ['ban', 'id-u-co-pinyin', 'de-ID'];
let val = Intl.DateTimeFormat.supportedLocalesOf(geeks);
console.log(val);
</script>

Output:

Array ["id-u-co-pinyin", "de-ID"]

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

  • Google Chrome
  • Edge
  • Firefox
  • Opera
  • Safari

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!

My Personal Notes arrow_drop_up
Recommended Articles
Page :