I am faced with a scenario where I have an array object structured as follows
[
{
id: 123,
startdate: '2022-06-05',
enddate: '2023-04-05'
},{
id: 123,
startdate: '2021-06-05',
enddate: '2021-04-05'
}
]
The task at hand is to introduce a new key isHistory
based on whether the start date falls within the current year. Referring to the example above, the desired outcome should look like this
[
{
id: 123,
startdate: '2022-06-05',
enddate: '2023-04-05',
isHistory: false
},{
id: 123,
startdate: '2021-06-05',
enddate: '2021-04-05',
isHistory: true
}
]
I am currently attempting to iterate through the object but I am struggling with how to compare each start date during the process and append a new entry. Any insights or suggestions on how to approach this challenge would be greatly appreciated.