How to shorten switch case block converting a number to a month name?

what about not to use array at all :)

var objDate = new Date("10/11/2009"),
    locale = "en-us",
    month = objDate.toLocaleString(locale, { month: "long" });

console.log(month);

// or if you want the shorter date: (also possible to use "narrow" for "O"
console.log(objDate.toLocaleString(locale, { month: "short" }));

as per this answer Get month name from Date from David Storey


Define an array, then get by index.

var months = ['January', 'February', ...];

var month = months[mm - 1] || '';