You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//第一种
for (let i in a) {
setTimeout(() => {
console.log(a[i]);
}, i * 1000 + 1000);
}
//第二种
function sleep(time) {
return new Promise((resolve, reject) => {
setTimeout(resolve, time);
});
}
(async function test(arr) {
for (var i in arr) {
await sleep(1000);
console.log(a[i]);
}
})(a);
The text was updated successfully, but these errors were encountered:
第一秒输出1,第二秒输出4。。。
a = [1, 4, 5, 7, 9];
The text was updated successfully, but these errors were encountered: