I am currently iterating through a two-dimensional array to populate a map. The map is using the [i,j] indices as keys and the corresponding arr[i][j] values as values:
const arrMap = new Map()
for(let i = 0; i < arr.length; i++){
for(let j = 0; j < arr[i].length; j++){
arrMap.set([i,j],arr[i][j]);
}
}
After logging the Map, it appears to have been set correctly with pairs like: [0,0] => "A"
.
However, when I try to retrieve the value using: arrMap.get([0,0])
, it returns undefined. How can I access the value "A" from arrMap?
An example array I would iterate through is:
[ ["A","B","B"],["A","A","A"] ]
There is a similar question discussed here- Array as a javascript map's key?, but the answer provided did not clarify the issue for me.