loading...

re: How to get month list in your locale VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Using the 2nd parameter mapFn on Array.from instead of .map saves a spread on monthList function getMonthList(locales, format = "long") { const...

And since year is not a parameter, no need for const year declaration to get a monthname

new Date(0, monthIndex) will do, for ES Arrow function:

const getMonthList = (locale = "en", notation = "long" ) =>
  Array.from(
    Array(12).keys(),
    key => Intl.DateTimeFormat(locale, {
      month: {
         s : "short",
         n : "numeric"
      } [notation[0]] || "long"
    })
    .format(new Date(0, key))
  );


`

Cool, thanks!

For constructor of Intl.DateTimeFormat locales is optional param. No requirement to provide default value of locale.

code of conduct - report abuse