When I was solving a problem on Leetcode, I’ve defined an empty array. I tried push some numbers then I got this Errow. I don’t know why. My code here.
// r and c are already defined numbers,arr is already defined array.
let n = [[]]
let index = 0
for (let i = 0; i < r; i++) {
for (let j = 0; j < c; j++) {
n[i][j] = arr[index]
index++;
}
}
return n;
Leetcode told me n[i][j] = arr[index] had errow;
Anyone knows why? thanks.