const cache = {};
//adding key-value pair
cache.John = {lastName:"foo"}
//assigning John to a new variable
const John = cache.John;
//changing the cache object
cache.John.lastName = "bar";
console.log(John); // { lastName: 'bar'}
above code shows that even though an object value is saved to a variable and then changed, the variable value also changes.
For my code I need to use a better structure, like a Map, however, when Map value is changed, the reference stays set to the old value.
const cache = new Map();
cache.set("John",{lastName:"foo"});
const John = cache.get("John");
cache.set("John",{lastName:"bar"});
console.log(John); // { lastName: 'foo'}
Is there a way to also "update" the reference using Map? are there any other structures I could use that are mutable in JavaScript?