So I'm trying to increase the time out in a for loop, I followed the answer here setTimeout with Loop in JavaScript but the duration of the setTimeout is just not working in milliseconds when I output the date to check the time difference.
Code:
for (var count = 0; count < 12; count++) {
(function(num){setTimeout(function() {
console.log("Count = " + num + " Time: " + 1000 * num + " Stamp: " + new Date());
}, 1000 * num)})(count);
}
As you can see in the console, it's still firing the console.log
every 1000
instead of 1000 * count
.
I hope the above makes sense and hopefully someone can explain this behaviour.