`function getCurrentFinancialYear()
{
const thisYear = (new Date()).getFullYear();
const lastYear = thisYear-1;
return ${lastYear}-${thisYear.toString().slice(-2)};
}
console.log(getCurrentFinancialYear());`
This is giving the output only 2020-21
You should run the year calculation logic in a loop.
I have used Array.map to generate the 5 years and used Array.join to convert the Array s=as a string.
Working Fiddle
function getCurrentFinancialYear() {
const thisYear = (new Date()).getFullYear();
const yearArray = [0, 1, 2, 3, 4].map((count) => `${thisYear - count}-${(thisYear - count - 1).toString().slice(-2)}`);
console.log(yearArray);
return yearArray.join();
}
console.log(getCurrentFinancialYear());