how to call setinterval function only for 2 times code example
Example 1: javascript interval fixed number of times
// This will be repeated 5 times with 1 second intervals:
setIntervalX(function () {
// Your logic here
}, 1000, 5);
Example 2: javascript interval fixed number of times
var x = 0;
var intervalID = setInterval(function () {
// Your logic here
if (++x === 5) {
window.clearInterval(intervalID);
}
}, 1000);