I've read all the answers written before but none of them solved my issue.
After building an associative array from asynchronous calls I pass it to the function for building the html element. The associative array has assigned values, but when I try to reach them they return undefined.
Here is the piece of code that logs to console:
var buildStreamerHtml = function(thisNameInfo){
console.log("buildHtml: ");
console.log(thisNameInfo);
console.log("status[]: " + thisNameInfo['status']);
console.log("status.: " + thisNameInfo.status);
Here is the console log:
buildHtml:
Object
logo: "https://static-cdn.jtvnw.net/jtv_user_pictures/freecodecamp-profile_image-d9514f2df0962329-300x300.png"
status: "Offline"
title: "FreeCodeCamp"
url: "https://www.twitch.tv/freecodecamp"
userExist: "yes"
__proto__: Object
status[]: undefined
status.: undefined
Every single key (logo, status, title, url and userExist) from thisNameInfo array returns undefined when I try to access it.
What am I doing wrong? How to access the key value?
One of the previous answers suggested access as follows: thisNameInfo[0].status I've tried it and it gives an error because thisNameInfo is not defined as an array.
This is how the array is initialized at the beginning:
var thisNameInfo = {};
And this is one segment of the code where values are assigned. Keys are created at the same time.
return $.getJSON("https://wind-bow.glitch.me/twitch-api/channels/" + name,
function(dataChannel) {
thisNameInfo.url = dataChannel.url;
thisNameInfo.title = dataChannel.display_name;
thisNameInfo.logo = dataChannel.logo;
});
Here is the link to the complete code as per Bergi suggestion: