0

how can you slow down the cycle for of? Displays all values ​​at once

for (var [key, value] of Array.from(groups).reverse()) { 
    
    setTimeout(function(){     // this does not work
    console.log('test');
    }, 3000);
    
    }
  • [Related problem with potentially useful solution](https://stackoverflow.com/questions/33289726/combination-of-async-function-await-settimeout?rq=1) – GolezTrol Jan 17 '21 at 22:24

1 Answers1

1

You can use a couple asynchronous functions

const delay = async time => new Promise(resolve => setTimeout(resolve, time))

;(
 async () => {
for (var [key, value] of Array.from(groups).reverse()) { 
    
     await delay(3000)
     console.log('test')
    }
}
)() 
Uzair Ashraf
  • 1,171
  • 8
  • 20