2 ms·
What do you mean by "why won't it work on objects"? Objects work fine as Set members. const a = {} const b = {} const set = new Set([a]) set.ha
by tshaddox 3y ago
What do you mean by "why won't it work on objects"? Objects work fine as Set members.
const a = {}
const b = {}
const set = new Set([a])
set.has(a)
// true
set.has(b)
// false
- leosanchez 3y agoAFAIK there is no mechanism to do the following const a = { value: 1 } const b = { value: 1 } const set = new Set([a, b]) set.size will be 2 as JavaScript checks for reference equality and has no mechanism check equality on a specific property