I am attempting to flatten an array and remove duplicates in one step using reduce
and a Set
but the array is flattened but the duplicates remain.
The related answer speaks to removing duplicates from an array but I would like to flatten and remove duplicates in one step, so I would suggest this might not be a duplicate question.
const wells = [
[{
id: 1,
name: 'well one'
},
{
id: 2,
name: 'well two'
},
{
id: 3,
name: 'well three'
},
],
[{
id: 2,
name: 'well two'
},
{
id: 3,
name: 'well three'
},
{
id: 4,
name: 'well four'
},
],
];
const uniqueflattenedWells = wells.reduce(
(a, b) => Array.from(new Set(a.concat(b))), [],
);
console.log(uniqueflattenedWells)