JSFiddle - React, Tailwind, and code Playground
by Arvind Pal
JavaScript
const quarters = [];
// Get current year and quarter
const now = new Date();
const currentYear = now.getFullYear();
const currentQuarter = Math.floor((now.getMonth() + 3) / 3);
// Loop through each year from 1991 to current year
for (let year = 1991; year <= currentYear; year++) {
// Loop through each quarter in the year
for (let quarter = 1; quarter <= 4; quarter++) {
// If it's the current year, only add quarters up to the current quarter
if (year === currentYear && quarter > currentQuarter) {
break;
}
quarters.push(`${quarter}Q${year}`);
}
}
console.log(quarters);