How can I remove duplicate assets from the list?
Please refer to the image for clarification. I attempted to use map and filter functions, but encountered an issue where additional attributes were lost. The desired outcome is to maintain the structure while eliminating any duplicated IDs within the assets[] array.
let known = new Set();
let listArrayDoc = this.documentsfiltered.map(subarray => subarray['assets'].filter(item => !known.has(item.id) && known.add(item.id)));
[
{
"id": 198406,
"description": "4. Monitor, assess, discuss and report on the implementation of all Development Agenda Recommendations",
"additionalInfo": [],
"assets": [
{
"id": 22116,
"name": "Completion Report of the Development Agenda (DA) Project on Tools for Successful DA Project Proposals.",
"isActive": true,
"sizekb": null,
"isLocal": false,
"type": "FILE",
"url": ""
},
...
],
"refId": null
},
...
]
The desired result should have the last assets empty.
[
{
"id": 198406,
"description": "4. Monitor, assess, discuss and report on the implementation of all Development Agenda Recommendations",
"additionalInfo": [],
"assets": [
{
"id": 22116,
"name": "Completion Report of the Development Agenda (DA) Project on Tools for Successful DA Project Proposals.",
"isActive": true,
"sizekb": null,
"isLocal": false,
"type": "FILE",
"url": ""
},
...
],
"refId": null
},
...
]