loading...

Print sorted elements of an array using setTimeout

318097 profile image Mehul Lakhanpal ・1 min read
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.

InstagramFacebook

Micro-Learning ● Web Development ● Javascript ● MERN stack

codedrops.tech

Discussion

pic
Editor guide