Search code examples
javascriptcleartimeout

JavaScript: Multiple clearTimeout in array


I have an array with timeout id's. What is the most elegant way to clear all of them at once? Is there a more efficient style than this?

waitHandler[1] = setTimeout('doSomethingA()', 2000);
waitHandler[2] = setTimeout('doSomethingB()', 2000);
...

for (var i=1; i < waitHandler.length; i++) {
    clearTimeout[i];
}

Solution

  • waitHandler.forEach(clearTimeout);