In JavaScript, I try the following:
let set1 = new Set([1]);
let set2 = new Set([2]);
let obj = {};
console.log("obj[set2] gives: ", obj[set2]);
obj[set1] = "Should be set1";
console.log(obj);
console.log("obj[set2] gives: ", obj[set2]);
It appears, that instead of treating the Set object as a key, it uses the string "[object Set]" as the key, thus making all Sets identical if used as keys. Why is this the correct behavior? Is there a way to use a Set as the key of an object, so I can look up a value associated with a particular Set? Thanks!