Here are two arrays that I have:
X = [
{
"id": "123a",
"month": 5,
"markCount": 75
},
{
"id": "123b",
"month": 6,
"markCount": 85
}
]
Y = [
{
"id": "123a",
"month": 4,
"markCount": 45
},
{
"id": "123b",
"month": 3,
"markCount": 65
},
{
"id": "123c",
"month"": 2,
"markCount": 55
}
]
The Goal
I want to combine array 'X' with array 'Y' to form a new array Z. Array Z should contain all the unique objects from 'Y' and update any common id values with information from array 'X'.
I attempted using the set function, but it did not return only the unique items:
Z = [...new Set([...X, ...Y])]
Z = [
{
"id": "123a",
"month": 4,
"markCount": 75
},
{
"id": "123b",
"month": 3,
"markCount": 85
},
{
"id": "123c",
"month": 2,
"markCount": 55
}
]