For Loop With Async Await in JavaScript(ES6)
November 24, 2021
For Loop With Async Await in JavaScript(ES6)
const BitFrit= async(n)=> {
for (let i = 0; i < n; i++) {
const t = Math.random() * 1000
const x = await new Promise(r => setTimeout(r, t, i))
console.log (i, x)
}
return 'done'
}
BitFrit(5)
.then(console.log)
.catch(console.error)