While trying to add new elements to the array I have, I get the error "Uncaught TypeError: Cannot set properties of undefined (setting '1')".
var arry = [[[[]]]],
i1 = 0,
i2 = 0,
intervalRate = 1000;
turn = 0, a = 10, b = 5;
for(i = 0; i < 2; i++) arry.push([]);
setInterval(() => {
arry[turn][i1][i2] = ([a, b]); //the error comes in this line
i2++;
if(i2 % 5 == 0 && i2 != 0){
i1++;
i2 = 0;
arry.push([]);
}
turn++;
if(turn == 3) turn = 0;
a += 5; b += 5;
}, intervalRate);
How can I solve this?
arry.push([])only adds an empty array to yourarry, so when you try to access the array in that array, it doesn't exist. arry is 2 levels deep, but you're only adding 1 level with this line.