How do I set elements of subarrays e.g.
var arr = [[1, 2, 3], [1, 2, 3], [1, 2, 3]];
var secondArr = [];
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
secondArr[i][j] = 5;
}
}
When I run it, it throws an error “Uncaught TypeError: Cannot set property ‘0’ of undefined”.
You can do this when the array is only 1d, then why not 2d arrays?