Hi, I’m trying to use MVC for the twitch project…
The below appears to work when model.requestTwitchStreamers() is called, and does return an array of 8 objects, however on stepping through it in Chrome devtools, streamObjects is always an empty array: [ ]. I expected to see it get larger by one each time the forEach loops goes through. I think I must be doing something wrong. Can anyone explain please?
Thanks,
Tim
var model = {
streamerNames: ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"],
requestTwitchStreamers: function() {
var streamObjects = [];
this.streamerNames.forEach(function(streamer){
var twitchApiUrl = 'https://api.twitch.tv/kraken/streams/' + streamer + '?callback=?';
$.getJSON(twitchApiUrl, function(data) {
streamObjects.push(data);
});
});
return streamObjects;
}
};