![](/img/trans.png)
[英]How do I wait for the API response in Node JS before executing next line
[英]How do I wait before executing the next line of code?
在執行后面的代碼( console.log('2 select question')
)之前,我需要腳本停止並等待 3 秒。
var i = 0,
count = 5;
function f() {
if (i < count) {
i++;
console.log('Continue 1')
setTimeout(f, 1000);
} if (i >= count) {
console.log('2 select question')
console.log('3 select answer')
i = 0;
}
}
f();
你好,我不知道我是否理解你,但試試這個:
var i = 0,
count = 5;
function f() {
if (i < count) {
i++;
console.log('Continue 1')
setTimeout(f, 1000);
}
else if (i >= count) {
console.log('2 select question')
console.log('3 select answer')
i = 0;
}
}
f();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.