I've been searching how to use the setTimeout function inside a loop but the documentation about this stuff seems limited, I want to make a setTimeout inside a for loop which itself is embedded in a while loop. It seems the browser executes the setTimeout only once as well as this code show it.
var value = 0
var arr = [65, 59, 80, 81, 56, 70, 72, 89, 23, 11, 4, 92, 87, 84, 50, 57, 59, 44, 49, 39, 35, 32, 0]
while(value < 10){
const span = document.createElement('span')
span.innerText = value
setTimeout(() => {
document.getElementById('spans').appendChild(span)
},1000)
value++
}
can anyone explain this behaviour, and how to proceed to get setTimeout executing every inside the loop.
Is setTimeout executed in async mode.