Skip to content
Advertisement

Generate an array of years with duplicates of each year + labeled season

How do i dynamically generate an array of years starting from 2004 till the current year, with each year labeled with “Spring” and “Fall” like in the attached picture?

enter image description here

Thank you!

Advertisement

Answer

You can easily achieve this result using flatMap. If you don’t care about the current year’s season then you can get all results up to the current year.

JavaScript
JavaScript

If you want results according to current year’s spring and fall

spring runs from March 1 to May 31

fall (autumn) runs from September 1 to November 30

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement