I have a map as follows:
let map = new Map();
map.set(\"a\", 1);
//Map is now {\'a\' => 1}
I want to change the value of a
The way you do it is fine. That is how you need to do it if you are working with primitive values. If you want to avoid the call to map.set
, then you must revert to a reference to a value. In other words, then you need to store an object, not a primitive:
let map = new Map();
map.set("a", {val: 1});
And then incrementing becomes:
map.get("a").val++;