Asked 4 years ago
18 Nov 2020
Views 688
iPhone-coder

iPhone-coder posted

Window setInterval() Method

how to use Window setInterval() in javascript ?
css-learner

css-learner
answered Nov 30 '-1 00:00

setInterval() method used for the calling function or evaluates an expression after or at specified intervals


setInterval(function(){ alert("array"); }, 2000);


above code prompt alert after every 2 second

how to stop running the setInterval ?
untill clearInterval() is called, or the window is closed , setinterval() keep running in the background.



Phpworker

Phpworker
answered Nov 30 '-1 00:00



setInterval(function, milliseconds, param1, param2, ...)

first argument is function
second argument is interval in miliseconds , 1000ms =1 second
setinterval keep calling function for each interval

other argument passed as parameters to the function


var interval =2000; //2 sec
setInterval(newfunc, interval);
function newfunc(){
       alert("me here");
}

it show alert at every 2 sec.
Post Answer