N
N
Nikita_Migushev2019-11-20 10:58:17
JavaScript
Nikita_Migushev, 2019-11-20 10:58:17

How to get object or array with months?

The most obvious option is to take and register everything manually:

var months = {
        01: "January",
        02: "February",
        03: "March",
        04: "April",
        05: "May",
        06: "June",
        07: "July",
        08: "August",
        09: "September",
        10: "October",
        11: "November",
        12: "December"
    }

But how can you get a similar object or array without writing the months manually, and do it in pure JS without libraries?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-11-20
@Nikita_Migushev

[...Array(12)].map((n, i) => new Date(0, i).toLocaleString('en-US', { month: 'long' }))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question