by tibbar · 2y ago · 0 comments
objects = {}
items1 = ["a", "b"]
items2 = ["a", "b"]
objects[items1] = 1
objects[items2] = 2
then objects[items1] will return 1, and objects[items2] will return 2, but objects[items1] !== objects[items2].EDIT: Sorry, this only works for dictionaries that are Maps, not Objects! See the responses. My fuzzing about in the console led me astray; you should start with `objects = new Map()` instead of `objects = {}`.
> o = { [{}]: 1 }
{ '[object Object]': 1 }
> k = { toString() { return 'a' } }
{ toString: [Function: toString] }
> o = { [k]: 1 }
{ a: 1 } new Proxy(
{},
{
get(target, property) {
return typeof property
},
},
)[{}] === 'string'With a map it works like you described:
objects = new Map()
items1 = ["a", "b"]
items2 = ["a", "b"]
objects.set(items1, 1)
objects.set(items2, 2)Thanks for taking the time to explain, everybody