you can use promise chain,just like this

```

const waitFor = (ms) => new Promise((r) => setTimeout(r, ms));

const start = () => {

let next = Promise.resolve();

for (const element of array) {

next = next.then(() => waitFor(1000)).then(() => console.log(element));

}

next.then(() => console.log('done'));

};

start();

```

--

--

--

Develop with pleasure!

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alan He

Alan He

Develop with pleasure!

More from Medium

All Cancer Types and Even Stage 4 Cancers Can Be Healed by Oxygen Radiation

(06/24/22) -$52.81 — $TBLT

Rest in Treats

網路通訊