Below written javascript code runs asynchronously and produces output in the following format.
const check = () => {
const arr = [3,2,1]
arr.forEach(async (val) => {
await setTimeout(() => console.log(val), val*1000)
})
}
check();
The actual output is:
1
2
3
But I want output in the following format:
3
2
1