Sets are supposed to contain unique objects, but it doesn't work for objects in javascript.
var set = new Set()
<- undefined
set.add({name:'a', value: 'b'})
<- Set {Object {name: "a", value: "b"}}
set.add({name:'a', value: 'b'})
<- Set {Object {name: "a", value: "b"}, Object {name: "a", value: "b"}}
It works for primitives
var b = new Set()
<- undefined
b.add(1)
<- Set {1}
b.add(2)
<- Set {1, 2}
b.add(1)
<- Set {1, 2}
So how do I get it to work with objects? I get the fact that they are different objects with the same values, but I'm looking for like a deep unique set.
EDIT:
Here's what I'm actually doing
var m = await(M.find({c: cID}).populate('p')) //database call
var p = new Set();
m.forEach(function(sm){
p.add(sm.p)
})
This is to get a unique list of sm.p