0

I have a function called printLetters which prints letters after 1000ms. I expected it to print letters one at a time with a 1000ms delay, but it prints all letters at once. How do I make it resolve each with delay without async/await?

const printLetters = (letters) => {
  for (let i = 0; i < logs.length; i++) {
    delay(1000).then(() => {
      console.log(logs[i]);
      })
  }
}

const delay = (t) => {
  return new Promise(res => setTimeout(res, t))
}

const arr = ['a','b','c']

printLetters(arr)
D Park
  • 504
  • 10
  • 19

0 Answers0