const arr = [4, 9, 2, 20, 1, 12];
arr.forEach(num => {
setTimeout(() => console.log(num), num);
});
Output:
1
2
4
9
12
20
Thanks for reading 💙
Follow @codedrops.tech for daily posts.
Instagram ● Facebook
Micro-Learning ● Web Development ● Javascript ● MERN stack
codedrops.tech
Top comments (1)
This ain't a good approach, what if the array has bigger numbers?
Having a sort function inside of the setTimeout is better.