You have a second for
loop inside your function, which infinitely increases i
. Replace i
with j
or any other variable name in any of the two for
loops and it will work as expected.
You could use the same variable name, i
if you declare them locally inside the for loop using the let
keyword, which declares variables only in the current block.