I'm struggling with something that should be very simple. I have an array of objects. I need to remove duplicate from this array based on the id property. So I want to create a Set containing my ids, like this:
let myArray = [{
id: 10,
other: "bla"
},
{
id: 15,
other: "meh"
},
{
id: 10,
other: "bla"
}
]
let indexes = new Set();
myArray.forEach(a => indexes.add(a.id));
console.log('indexes list', indexes)
But indexes is always empty. What am I doing wrong? Thanks.
EDIT: I chose @Hyyan Abo Fakher's as correct answer because he was right, but the suggestion in @bambam comment was a great solution to the whole problem. Thanks to everyone.

console.log(Array.from(indexes))Anyways. Just using reduce will be easierconst unique = arr.reduce((a,b) => a.find(({id}) => id === b.id) ? a : a.concat(b) , []);this.myArrayisn't empty?