我希望我的for循环不应该立即执行,而是在每次迭代后等待超时.例如:
for(var i=0; i<10; i++) {
console.log(i);
//wait for 1000
}
Run Code Online (Sandbox Code Playgroud)
我在堆栈溢出中发现了许多像这样的解决方案:
for (var i=0;i<=10;i++) {
(function(ind) {
setTimeout(function(){console.log(ind);}, 3000);
})(i);
}
Run Code Online (Sandbox Code Playgroud)
但是在所有实现中,循环最初等待3000毫秒,然后立即执行整个for循环.有没有办法在等待1000毫秒后调用每个迭代.