I'm looping through a two-dimensional array to set the values to a map. I'm storing the [i,j] indices as the map key, and the actual arr[i][j] value as the map value:
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]);
}
}
At this point I've "console-logged" the Map, and it seems to have set correctly with pairs like the following: [0,0] => "A"
.
Then I try to access the map value: arrMap.get([0,0])
but this returns undefined. How can I access the "A" from my arrMap?
Example array that I'd be looping through would be [ ["A","B","B"],["A","A","A"] ]
There's a very similar question here- Array as a javascript map's key? but the answer didn't make sense to me.