I have this array of objects and I am wanting to filter out where myDatas.items.flaggedItem is not null and at the same time remove the duplicates where myDatas.items.id are the same. So in this instance I would only expect 2 to be returned
"myDatas":[
{
"id": "id1",
"items":[
{
"id": "idOne",
"flaggedItem": null,
},
{
"id": "idTwo",
"flaggedItem": 1,
},
},
{
"id": "id2",
"items":[
{
"id": "idTwo",
"flaggedItem": 1,
},
{
"id": "idOne",
"flaggedItem": 2,
},
}
]
I have this, but unable to find a good way to remove the duplicates. This accomplishes the first part where I am pulling only items where myDatas.items.flaggedItem is not null, but does not remove the duplicates.
let test1 = myDatas
?.map(myData => {
let test2 = myData.items?.filter(
items => items.flaggedItem || items.flaggedItem === 0
);
return { ...myData, items: test2 };
});
itemsarrays together to deduplicate it easily...