I am attempting to retrieve 8 JSON objects from 8 different URLs. I have stored the query string that needs to be modified in an Array, and I am looping through it using a for loop. Below is my code:
var index = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
var request = new XMLHttpRequest();
for (var i = 0; i < index.length; i++) {
var url = "https://wind-bow.glitch.me/twitch-api/channels/" + index[i];
request.open("GET", url);
request.onload = function() {
var data = JSON.parse(request.responseText);
console.log(data);
}
request.send();
}
At this point, my goal is to simply display each JSON object on the console. However, I am only able to display the last JSON with the last index item (noobs2ninjas).
Can anyone explain why this is happening? How can I retrieve all the JSON objects that I need?
Thank you