Everything I read online regarding this issue says the nested object doesn’t exist, but it seems to exist in my console logs. Why doesn’t it exist?
function nestedArr(a) {
var obj = {};
for (var x = 0; x < a.length; x++){
for (var y = 0; y < a[x].length; y++){
var value = a[x][y];
obj[value] = {row : x, col : y};
}
}
console.log(obj);
/*{ '1': { row: 0, col: 0 },
'2': { row: 0, col: 1 },
'3': { row: 0, col: 2 },
'4': { row: 1, col: 0 },
'5': { row: 1, col: 1 },
'6': { row: 1, col: 2 },
'7': { row: 2, col: 0 },
'8': { row: 2, col: 1 },
'9': { row: 2, col: 2 } }*/
console.log(obj[1]); //{ row: 0, col: 0 }
console.log(obj[1].row); //TypeError: Cannot read property 'row' of undefined
console.log(obj[1]["row"]); //TypeError: Cannot read property 'row' of undefined
}