DEV Community

Discussion on: Removing duplicates in an Array of Objects in JS with Sets

Collapse
 
mhasansiddiqui profile image
hasan

let array = [];
let singleEle = [];
const arr = [
{ id: 1, {questionId : { _id: "5e2016a1560d8c2aa842e65d"} }},
{ id: 1, {questionId : { _id: "5e1c211cc201f33834e7baf1"} }},
{ id: 1, {questionId : { _id: "5e201733560d8c2aa842e65e"} }}
];
arr.forEach(item => {
if (array[item.questionId._id] ) {

}
else{
array[item.questionId._id] = true;
singleEle.push(item)
}
});