Last active
September 17, 2015 09:09
-
-
Save jasdeepkhalsa/15acfca524bfd6846f27 to your computer and use it in GitHub Desktop.
Managing intervals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var intervals = []; | |
intervals.push(setInterval(function() { | |
console.log('apples'); | |
}, 100)); | |
intervals.push(setInterval(function() { | |
console.log('pears'); | |
}, 100)); | |
console.log(intervals); // Expect two unique IDs by setInterval referring to the specific interval instances | |
function clearIntervals() { | |
for (var i = intervals.length - 1; i >= 0; i--) { | |
clearInterval(intervals[i]); | |
intervals.splice(i, 1); | |
} | |
} | |
clearIntervals(); | |
console.log(intervals); // Expect an empty array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment