I am attempting to create an empty 2D array but encountering an issue where I receive an error stating "cannot set property of undefined". My approach involves dynamically determining the size of the array and populating it with different DOM objects at specific locations within the array. Could this be due to a mistake in how I initialized the array?
let gridArrayNumbers = [];
section.Layout.forEach(layout => {
gridArrayNumbers.push(layout);//eventually, this array will contain {2,3}
});
let gridArray: any [][] = [];
...
let e = document.createElement("label");
e.textContent = element.content;
gridArray[element.layout.row][element.layout.column] = e;//this is where the error occurs with 'undefined'