📜  settimeout inside loop - Javascript代码示例

📅  最后修改于: 2022-03-11 15:04:22.678000             🧑  作者: Mango

代码示例2
//you can leave the sleep constant
const sleep = (milliseconds) => {
  return new Promise(resolve => setTimeout(resolve, milliseconds))
}

const doSomething = async () => {
  for (/*for loop statements here*/) {
  //code before sleep goes here, just change the time below in milliseconds
   await sleep(1000)
  //code after sleep goes here 
    }
  }
doSomething();