Only the reference to the same object, the Map structure will treat it as the same key. If the key
in Map is an array, the get
method cannot read the key and returns undefined.
const map = new Map();
map.set(['a'], 111);
map.get(['a']) // undefined
How can I get the value 111
of the key ['a']
by get
method or any other way?
Correct approach for output:
const map = new Map();
map.set('a', 112);
console.log(map.get('a')); // 112
OR
const map = new Map();
var a=['a','b','c'];
map.set(a[0], 112);
console.log(map.get(a[0])); // 112