JavaScript setInterval immediately run

前端 未结 5 1947
梦如初夏
梦如初夏 2021-01-22 09:28

I found a solution to run interval in javascript immidiately, not waiting for a first \"timeout\"

setInterval(function hello() {
  console.log(\'world\');
  retu         


        
5条回答
  •  半阙折子戏
    2021-01-22 10:27

    In your code there is no way to perform the required task, instead follow the below approach:

    // Use function to perform the task.
    function doTask () {
    	console.log("...");
    }
    // Perform task for the first time.
    doTask();
    // On interval do task.
    setInterval(doTask, 2500);

提交回复
热议问题