I need to increment a var counter inside an $.each() loop. Here's my code:
ajaxCreateOrder = function(fileUrl, dataArray, numRecords) {
var loopIteration = 1;
var ajaxIterateDelay = 1000;
$.each(dataArray, function(key,val) {
setTimeout(function() {
doAjaxRequest(loopIteration, fileUrl, val, numRecords);
}, loopIteration * ajaxIterateDelay);
loopIteration++;
});
}
All is working as expected, except that loopIteration does not increment. What am I doing wrong? Thanks.