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

How old bookies make money off you by setting the odds and how WagerGang fixes this AND MORE….

Smiling

CS371p Spring 2022: Lisa Alexander : Final Entry

Is it Okay to have Sex or get intimate with your best friends or BFFs?