I'm trying to use a map
instead of an object for some data that I'd like to have complex keys. Since I can use an object as a key in a map, this seems cleaner to me than having an object key that is a stringified and concatenated key eg,
const datum = {
large: 'chunk',
of: 'data'
}
const ids = [10797, 11679, 10679, 10160, 11681, 01802]
const view = 142171
const selectedDateRange = 'ONE_MONTH'
const objKey = {
ids,
view,
selectedDateRange
}
const data = new Map()
data.set(objKey, datum)
console.log(data.get(objKey)) // this works and i see the data
const objKeyRef = objKey
console.log(data.get(objKeyRef)) // also works and i see the data
However it won't work if the key given to get
doesn't ===
the key it was set with.
data.get({
ids,
view,
selectedDateRange
}) // undefined
This is clear in the documentation (though i don't really see it explained why). I'm wondering if there is a way around it. I'd like to be able to compose the keys at a later time and get their value from the map.