I am running this JS code in my Browser Console to display some names from a table in an interval of 4 seconds. After the loop has run X amount of times, it should clear the interval.
$(document).ready(function() {
for(var j = 0; j < 2; j++) {
var refreshIntervalId = setInterval(function(){var td = $("tr td:first-child");
for (var i = 6; i < 26; i++){
console.log(td[i].innerText);
}},4000);
$("#idc4").click();
}
clearInterval(refreshIntervalId);
});
I've saved the interval ID in the variable refreshIntervalId and I am calling the clearInterval function after the loop with this ID, but my interval keeps running, displaying the same names in the console. Is the variable out of scope? Or does the browser console have some limitations when it comes to this?