I have made $.getJSON requests two the two apis and received back an array with eight arrays inside. Each of the inner arrays contains two objects, one for user data and another for the stream data.
Problem is I an unable to access any data from the internal array as shown in the code below.
$(document).ready(function() {
var users = [
"ESL_SC2",
"OgamingSC2",
"cretetion",
"freecodecamp",
"storbeck",
"habathcx",
"RobotCaleb",
"noobs2ninjas"
];
getUserInfo(users);
});
//Getting user info from the two urls : with parameter streams and user
function getUserInfo(users) {
allData = [];
users.forEach(element => {
let info = [];
$.getJSON(
`https://wind-bow.gomix.me/twitch-api/users/${element}?callback=?`,
function(data) {
info[0] = data;
}
);
$.getJSON(
`https://wind-bow.gomix.me/twitch-api/streams/${element}?callback=?`,
function(data) {
info[1] = data;
}
);
allData.push(info);
});
renderResponse(allData);
}
// Render data to html
function renderResponse(allData){
let output = ``;
console.log(allData);//works
//console.log(allData[0][0].display_name);//=> Checking to see if I can access the data but getting an uncaught type error instead
allData.forEach(element => {
console.log(element[0].display_name);
});
}```
Kindly help..a bit frustrated.