Browser - Web API - setInterval

1 - About

How to execute a piece of code at regulier interval.

3 - Example

  • Increment and log the variable i every 3 seconds
let i = 0;
$intervalFunctionId = setInterval(()=>{
    i++;
    if (i<10) {
        console.log("Executed after "+i*3 +" seconds");
    }
}, 3000) // every 3 seconds
  • Stop the interval function with a setTimeout after 9 seconds.
setTimeout(()=>{
    window.clearInterval($intervalFunctionId);
    console.log("Interval function "+$intervalFunctionId +" was cleared");
}, 9000) // after 9 seconds

4 - Management

4.1 - Clear

clearInterval function gets the return id value of the setInterval function.


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap