setInterval and clearInterval, How to run only 1 time?

function, javascript, jquery

Solution

Use the setTimeout method if you only want it to run once.

Example:

 setTimeout(function() {
      // Do something after 5 seconds
 }, 5000);

Problem

I only want to run the function 1 time. ``` timerA = setInterval(function() { //codes.. clearInterval(timerA); }, 2000); ``` I want to call the function inside setInterval only 1 time. How can I do it with setInterval and clearInterval? Or is there another technique to do it?

Original source

Related problems