I have the following code:
let j = 0;
for(i = 0; i < board[0].length; i++)
{
j = i;
check_row(board[i], i, tiles);
i = j;
}
The board is an array containing 5 arrays of size 5:
[[0,1,2,3,4],[0,1,2,3,4],[0,1,2,3,4],[0,1,2,3,4],[0,1,2,3,4]]
Tiles is a nodeArray of size 25 if it’s relevant.
The check_row(…) function currently just contains console.log("test")
If I remove the
i = j
then check_row will only execute once, but if I keep i = j, then the loop will work as normal and call check_row() the intended 5 times, once for each row. I do not understand why passing the iterator breaks the loop. If I pass j instead of i and remove i = j, then I run into the same problem.
Any help would be apppreciated!
2
Answers
Have you declared i in somewhere else too, it might be the problem with not adding let at the start of the for loop?
Code used to try to reproduce (assuming length is 5):
Unable to reproduce removing
i = j
as said, even when missing thelet
fori = 0;
. The problem must be elsewhere in your code.Setting
j = i
theni = j
is useless as pointed out by @derpirscher.If you need to store
i
, onlyj = i
is required.