Web APIs
setInterval()
Schedules repeated callbacks subject to host scheduling. Stop the repeating timer when no longer needed. Callback count does not guarantee exact elapsed time.
Formal Syntax & Structure
javascript syntaxjavascript
setInterval(callback, delay, ...args)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| callback | function | Repeated callback. |
| delay | number | Requested interval in milliseconds. |
| args | any[] | Callback arguments. |
Return Value
host-specific handle
Handle for the interval.
Working Example
Example Snippetjavascript
let count=0; const id=setInterval(()=>{console.log(++count); if(count===2) clearInterval(id);},1);