With following for loop
for(var i = 0; i<10; i++) {
setTimeout(function () {
console.log(i);
},10);
}
I'm trying to print all values of 'i' inside setTimeout(); With above code i know before reaching to console.log() all 'i's are 10 as setTimeout is async.
So I used below code
for(var i = 0; i<10; i++) {
setTimeout(console.log(i),10000);
}
I did got output 1-9 but not after 10sec. How can i get values of 'i' from 1-9 with out storing in a different variable outside setTimeout. Is it possible to do so?