Skip to content

Instantly share code, notes, and snippets.

@jasdeepkhalsa
Last active September 17, 2015 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdeepkhalsa/15acfca524bfd6846f27 to your computer and use it in GitHub Desktop.
Save jasdeepkhalsa/15acfca524bfd6846f27 to your computer and use it in GitHub Desktop.
Managing intervals
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