I am getting old or just rusty or both, but I hang my head in shame as I bring this here because there must be something really, really simple that I am missing.
I am writing this using Google Apps script in Sheets.
Why does this fail once I reach j = 2? I have tried declaring the array in every different way I can think of, nothing gets past j=2. Wth am I missing? It's something dumb I know it.
function myFailure() {
for (var j = 0; j < 10; j++) {
for (var k = 0; k < 31; k++) {
var item = 'Item '+k;
let thisItem = new Array([],[]);
thisItem[j][k] = item; //the problem is happening here, once j=2 but why
console.log(j,k);
console.log(thisItem[j][k]);
}
}
}
myFailure();
console.log(thisItem)and I think this will point you out to the solution ;)new Array([], [])creates an array with 2 arrays in it. Whenjis 0 or 1, it works, but not when it's 2.myArray = []format instead ofnew Array(). Check out this answer as a reference.