I'm trying to call a timed function under a number of incrementing variables. The code below executes the function the correct number of times, but only returns the last value of the for loop each time it is called. How would I have the updateBtn function execute using the incrementing loop value?
for(var i = 0; i < myArray.length; i++) {
setTimeout(function() {
updateBtn(i);
}, 6000)
}
function updateBtn(j){
alert(j);
}