I'm facing a problem with two arrays of objects structured like this...
const planned = [
{
'2023-01-06': 46,
'2023-01-04': 45,
'2023-01-05': 43,
'2023-01-07': 53
}
]
const actual =[
{
"2023-01-07": 12,
"2023-01-06": 16,
"2023-01-04": 14,
"2023-01-08": 10,
"2023-01-05": 12,
"2023-01-03": 10
}
]
I want to merge them into a single array of objects separating the date and its corresponding value. This is how I expect the final array to look:
const transformed = [{
date:"2023-01-03",
actual:10,
planned:0,
},{
date:"2023-01-05",
actual:10,
planned:5,
},{
date:"2023-01-06",
actual:16,
planned:46,
},....
] I've tried coming up with a solution, but I'm struggling with the logic... Can anyone provide me with some guidance on how to tackle this? Is there a way to utilize the reduce prototype array or any other built-in methods for this task? Any assistance would be greatly appreciated.