I have this code :
let startDate = moment().subtract(4, 'years');
let endDate = moment().endOf('month');
let months = [];
let month = startDate;
while (month <= endDate) {
if (months.includes(month.format('YYYY'))) {
months.push([month.format('YYYY'), month.format('MM/YYYY')]);
} else {
months.push(month.format('YYYY'), month.format('MM/YYYY'));
}
month = month.clone().add(1, 'months');
}
console.log(months);
I want to get something like :
[
"2016" : ["09/2016", "10/2016", "11/2016", "12/2016"],
"2017": ["01/2017", "02/2017"...],
"2018": [....]
]
Have you an idea about that. My function is not working properly.