I'm working on some timeout in jQuery but I got a problem with my timeout value. So, I got an array of value (Ex : ["2490", "4200"]), and I want my timeout to print the value of the array after 2490ms, then go back to 0 and finaly print the next value of the array after 4200ms. But it never go back to 0
Actualy, this is the jQuery code :
var array = ['2490', '4200'];
var mytimeout;
for (var i = 0; i < array.length; ++i)
{
doTimeout(i);
clearTimeout(mytimeout);
}
function doTimeout(i) {
mytimeout = setTimeout(function() {
$('#text').append(array[i]);
}, array[i]);
}
JSFIDDLE : https://jsfiddle.net/2aftscou/
So everything seems to work except the fact that I want my timer to be reinitialize at 0 when it ends (that's why I've used clearTimeout(), but it doesn't work in this case).
I really don't know what to do
timeris cleared, callback will not be called..setTimeout()only executes once in any case,clearTimeout()is only needed if you want to cancel the one timeout before it happens.setInterval()is repeating.