My javascript is horrible, I am a C# dev but here we are. So I need to loop through every month between a start year and month to an end year and month.
The startMonth and startYear will always be 1 and 2010 respectively.
I have the following solution at the moment:
//Get the current year and month
let currentTime = new Date();
let currentYear = currentTime.getFullYear();
let currentMonth = currentTime.getMonth() + 1;
//Set starting year and month
let startYear = 2010;
let startMonth = 1;
//Loop through the years and months
for (let i = startYear; i <= currentYear; i++){
if (i === currentYear ){
for (let k = 1; k <= currentMonth; k++){
//Do work
}
} else {
for (let j = startMonth; j <= 12; j++){
//Do work
}
}
}
Does someone have a better solution? I feel like this is really clunky. I don't mind using third party packages so if moment or something will work then I'll use it.