I'm attempting to launch severals setInterval functions "at once". I've got a for loop which call a function indexed, which contains the setInterval.
I've looked for answer both here: JavaScript closure inside loops – simple practical example and here: setInterval with loop time
but i'm still struggling with no success...
I've checked tab and tab2, both works if I read them with console.log outside of the setInterval function
here is my code :
var tab = <?php echo json_encode($matrice); ?>;
var tab2 = new Array();
var funcs = [];
var countDownAction = new Array();
function countDown(i)
{
countDownAction[i] = setInterval(function(i)
{
// some actions
}, 1000);
}
for(var i = 0; i < tab.length; i++)
{
tab2[i] = [];
tab2[i]['hours'] = tab[i]['hours'];
tab2[i]['minutes'] = tab[i]['minutes'];
tab2[i]['seconds'] = tab[i]['seconds'];
funcs[i] = countDown.bind(this, i);
}
for(var j = 0; j < tab.length; j++)
{
funcs[j]();
}