How can we remove duplicate items for the root of an array using javascript. The code below removes duplicate items that are nested in the array. I am hoping to remove the root duplicate.
let myItems = [{
"Visible": true,
"title": "Folder 1",
"Children": [{
"title": "item in folder",
"IsGIF": false,
"IsWeb": false
}]
},
{
"title": "item in folder",
"IsGIF": false,
"IsWeb": false
}
]
let stringArray = myItems.map(JSON.stringify);
let uniqueStringArray = new Set(stringArray);
let uniqueArray = Array.from(uniqueStringArray, JSON.parse);
console.log(uniqueArray);
//outputs:
[{
Visible: true,
title: 'Folder 1',
Children: [
[Object]
]
},
{
title: 'item in folder',
IsGIF: false,
IsWeb: false
}
]
Hoping to get the following output:
[
{
"Visible": true,
"title": "Folder 1",
"Children": [
{
"title": "item in folder",
"IsGIF": false,
"IsWeb": false
}
]
}
]