so I 'm having a strange bug here related to changing the month of a date object. here is the code.
let date = new Date();
let captions = [];
for (let i=0; i < 12; i++) {
let newDate = date;
newDate.setMonth(date.getMonth() - i);
let month = newDate.toLocaleString('default', { month: 'short' });
let year = newDate.getFullYear();
captions.push({month, year});
}
The thing is value of date variable is changing every loop. I can understand why.
Anyone?