Why is the value of i
in getscore() (which is a callback to the second api) non-sequential which results in the undesired output of my application?
function getscore(sid, mid, callback) {
fetch("https://dev132-cricket-live-scores-v1.p.rapidapi.com/scorecards.php?seriesid=" + sid + "&matchid=" + mid, {
"method": "GET",
"headers": {
"x-rapidapi-host": "dev132-cricket-live-scores-v1.p.rapidapi.com",
"x-rapidapi-key": "..."
}
})
.then(response => {
return (response.json());
})
.then(function(data2) {
callback(data2);
});
}
fetch("https://dev132-cricket-live-scores-v1.p.rapidapi.com/matches.php?completedlimit=6&inprogresslimit=7&upcomingLimit=9", {
"method": "GET",
"headers": {
"x-rapidapi-host": "dev132-cricket-live-scores-v1.p.rapidapi.com",
"x-rapidapi-key": "..."
}
}).then((response) => {
return response.json();
}).then((MyJson) => {
console.log(MyJson);
for (let i = 0; i < MyJson.matchList.matches.length; i++) {
//some opeerations
console.log(i); //sequential
getscore(matchid, function(data) { //callback second api
console.log(i); //non-sequential
});