I am faced with a scenario where I have two objects that share the key and value name of DateYMD. My intention is to merge these two objects and generate a new object from them.
Here is the data from the current objects :
[{
"Id": "1",
"date": "2024-12-05T00:00:00",
"DateYMD": 20241205,
"bookTimeFrom": "2024-12-05T08:00:00",
"bookTimeTo": "2024-12-05T13:00:00"
},
{
"Id": "2",
"date": "2024-12-05T00:00:00",
"DateYMD": 20241205,
"bookTimeFrom": "2024-12-05T14:00:00",
"bookTimeTo": "2024-12-05T18:00:00"
}]
I attempted to use the Object.assign method to accomplish this task, but it did not yield the expected results.
The desired output should look like this :
{
"date": "2024-12-05T00:00:00",
"DateYMD": 20241205,
"Id": ["1","2"],
"bookTimeFrom": ["2024-12-05T08:00:00", "2024-12-05T14:00:00"],
"bookTimeTo": ["2024-12-05T13:00:00", "2024-12-05T18:00:00"]
}