I have 2 arrays which is contains same id with different value (inside selected) My goal is to merge both become 1 array.
When I use spread operator like this:
data = [
...data.filter(
(a) => a.id === newData.id
),
newData];
It comes the data being override
First array
[
{
id: "A527CFFE",
selected: [
{
itemId: "A1",
text: "Selected 1"
}
]
}
]
Second array
[
{
id: "A527CFFE",
selected: [
{
itemId: "A2",
text: "Selected 2"
}
]
}
]
How can I make both of arrays become 1 ? the expected result:
[
{
id: "A527CFFE",
selected: [
{
itemId: "A1",
text: "Selected 1"
},
{
itemId: "A2",
text: "Selected 1"
}
]
}
]
What am I doing wrong in the above?
ids)?