Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptJavaScript Intl DateTimeFormat supportedLocalesOf() Method

JavaScript Intl DateTimeFormat supportedLocalesOf() Method

The Intl.DateTimeFormat.supportedLocalesOf() method is an inbuilt method in JavaScript that 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 accepts 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 has localeMatcher property. localeMatcher is the locale-matching algorithm to use. It has the values “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.

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

Example 1: In this example, we will see the use of the Intl.DateTimeFormat.supportedLocalesOf() method in JavaScript.

javascript




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


Output: 

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

Example 2: In this example, we will see the use of the Intl.DateTimeFormat.supportedLocalesOf() method in JavaScript.

javascript




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


Output: 

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

We have a complete list of Javascript Intl methods, to check those please go through the Javascript Intl Complete Reference article.

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

  • Google Chrome 24 and above
  • Edge 12 and above
  • Firefox 29 and above
  • Opera 15 and above
  • Safari 10 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

Recent Comments