How to using setTimeout in side loop javascript for wait a second and then process next loop ?
i tried to using setTimeout
in side for loop
javascript for wait a second and then process next loop, but it’s not work.
<script>
for (let i = 1; i < 3; i++) {
setTimeout(function(){
alert(i);
}, 2000);
}
</script>
When run code i want to get result like this
wait 2 second then alert “1
” wait 2 second then alert “2
“