Using Moment.js I would like to get all days in a month of specific year in an array. For example:
January-2014:
[
\"01-wed\",
\"02-thr\",
\"03-fri\",
\"04-s
I think that using the method moment(month).daysInMonth() to get the number of days in a month together with Array.from() to generate the array is the cleaner and performative way.
const getDaysByMonth = (month) => {
const daysInMonth = moment(month).daysInMonth();
return Array.from({length: daysInMonth}, (v, k) => k + 1)
};
let month = '2019-02';
console.log(`February => ${getDaysByMonth(month)}`);
month = '2019-06';
console.log(`June => ${getDaysByMonth(month)}`);
month = '2019-07';
console.log(`July => ${getDaysByMonth(month)}`);