Is there any way to run more than one setInterval () at the same time? Home
In my code, if I run the interval twice, the program goes into infinite loop, and on the console I get:
[1,2,3,4,5]
[1,2,3,4,5,6]
[1,2,3,4,5,6,7]
[1,2,3,4,5,6,7,8 ......] infinitely
arraya = []
arrayb = []
function interval(array, length, count) {
a = setInterval(function () {
count++;
array.push(count);
if (array.length > length) {
console.log(array.join(' '));
clearInterval(a);
}
}, 150);;
}
interval(arraya, 4, 0);
// interval(arrayb, 9, 0)