I am trying to store values in a JavaScript Map using an object as a key. However I am unable to access them using the get method provided by Map object. This is what I am trying to do -
let map1 = new Map();
map1.set({a: 1}, "valueforobject");
console.log(map1.get({a: 1})); //expected this to print valueforobject but got undefined
When I am logging the map itself however I can the that the value has been stored safely. How do I access this using the get method or any other way appropriate here?
{a: 1} !== {a: 1}... butvar a = {a: 1}; a === a;var a= {a:1}; map1.set(a, "valueforobject");console.log(map1.get(a));JSON.stringify({a:1})as the key