function x(){
for(var i=1;i<=5;i++){
setTimeout(function (i){
console.log(i)
},i*1000)
}
}
x();
I'm currently facing an issue with my code where instead of printing the variable i, it's showing "undefined". Can anyone provide assistance with this?
I've been exploring how to incorporate the setTimeout function within a loop, but the available documentation on this topic seems limited. I am keen on understanding how to implement a setTimeout within a for loop. Any guidance on this matter would be highly appreciated.