Twitch project, using MVC, forEach loop unexpected devtools output?!

Twitch project, using MVC, forEach loop unexpected devtools output?!
0

#1

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;
  	}
};

#2

I don’t know, works for me.


#3

Wow… it appears it was some Chrome extension I had that was messing with what I saw somehow. I’ve simply disabled them all and now I’m seeing it work! Wonder what else I’ve wasted time on that was a result of this!

@jenovs, thanks for checking!

Tim.