I have two chat message arrays, each representing messages for a given date. I must merge these two arrays into a single object with the same date format. The object should contain all messages from both arrays, with the messages for each date merged.
Here is the data:
const data1 = {
messages: {
"27-04-2023": [
{
id: "SOkXFGtTwh",
},
{
id: "i3NrqNyG9P",
},
{
id: "lCmxr4rc5T",
},
]
}
};
const data2 = {
messages: {
"27-04-2023": [
{
id: "V9QzRgl6ji",
},
{
id: "K5wfD-kX8W",
}
],
"24-04-2023": [
{
id: "tuarzhHPwH",
},
{
id: "cbxu_dAeAj",
},
{
id: "9xJpEJGUnm",
}
]
},
};
How to merge them to get the following output?
const data1 = {
messages: {
"27-04-2023": [
{
id: "SOkXFGtTwh"
},
{
id: "i3NrqNyG9P"
},
{
id: "lCmxr4rc5T"
},
{
id: "V9QzRgl6ji"
},
{
id: "K5wfD-kX8W"
}
],
"24-04-2023": [
{
id: "tuarzhHPwH"
},
{
id: "cbxu_dAeAj"
},
{
id: "9xJpEJGUnm"
}
]
}
};
What would be the best way to perform such task?