In my code -
function longForLoop(limit) {
var i = 0;
var ref = setInterval(() => {
console.log("\n-----------------------------\n");
normUrl = "https://sih-utils.herokuapp.com/normal?a="+qActualNormal +"&b="+qIdeal;
var obj;
fetch(normUrl)
.then(res => res.json())
.then(data => obj = data)
.then(() => console.log(obj))
console.log(obj);
i++;
if (i == limit) {
clearInterval(ref);
}
}, 2000);
}
longForLoop(2);
Following result is obtained -
When I run this code, it says obj not defined, I have 2 more similar calls to make to the same API below this and it returns some result that is stored in a variable, and in the end, I want to console.log the results obtained according to the order in which they were called.