[Edit]
+
0
-
0
js for loop with settimeout() example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22const doLoop = (start, stop, step, delay, callback) => { let i = start; const doIteration = () => { if (i < stop) { callback(i); i += step; setTimeout(doIteration, delay); } }; setTimeout(doIteration, delay); }; // Usage example: doLoop(0, 10, 1, 1000, (index) => console.log(index)); // prints values from 0 to 9 in the console every second // Where: // 0 - iteration start // 10 - iteration stop // 1 - iteration step // 1000 - delay between iterations (1s)