You need to know, this example is wrong

it's not work

1,2,3,4 will be output at the same time.

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

const start = async () => {

await array.forEach(async function (element) {

await waitFor(1000);

console.log(element);

});

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

Still a workaholic? 8 ways to give your mind a break

A Dark Window

dark, window, night, rain

Are You Being Hit By The Rising Cost Of Living?

A tribute to the iPod