I'm trying to run a setTimeout inside a for loop. I've followed recommendations to move the setTimeout into a separate function. However, everything seems to fire at once, at the end of the loop.
In this example, I'd like the console.logs to fire every second.
function setDelay(i) {
setTimeout(function(){
console.log(i);
}, 1000);
}
for (var i = 1; i <= 10; ++i) {
setDelay(i);
}