I am relatively new to TypeScript and currently working on one of my initial projects in Microsoft Makecode Arcade. I am attempting to populate an array as a class property using a loop.
class Game {
grid: number[][]
constructor() {
for (let i = 0; i < 20; i++) {
let row: number[] = []
for (let j = 0; j < 10; j++) {
row.push(0)
console.log(row)
}
this.grid.push(row)
}
}
}
An error message is displayed stating "Dereferencing null/undefined value", even though console.log(row)
displays the correct array [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]