A few points :
i
has the value of end of loop by the time the callback is called.- to iterate over an array using jQuery, use
$.each(array,
, not$(array).each(
- the function doesn't have to be defined in the loop
- each gives the index as second argument of the callback and as first argument the value.
So it seems that what you want is in fact this :
var indexArray = array(1,2,3);
var timerx = [];
$.each(indexArray, function( indexArrayValue, i ) {
timerx.push(setTimeout(function(){
console.log("test " + i + ' : ' + indexArrayValue);
}, (i+1) * 500000));
});