I'm spinning my wheels over here. How do I return the new value of onlinearray?
I want it so when I call the functions like so...
online()
I get the result onlinearray handed back to me.
function online(){
var offlinearray = [];
var onlinearray = [];
console.log('called online');
//foreach item in channels
codeLib.channels().forEach(function(item){
console.log(item);
// run gotJSON
codeLib.gotjson(item).done(function(result){
if (result.stream == null) {
// push into offline array
offlinearray.push(item);
console.log('OFFLINE array: '+ offlinearray );
}else{
// push into online array
onlinearray.push(item);
console.log('ONLINE array: ' + onlinearray); <--I can see values in console.log here
}
});
});
//console.log('inside: '+onlinearray);
return onlinearray; <---doing something wrong here.
}
gotjson is as follows...
Codelib.prototype.gotjson = function(channel) {
return $.getJSON("https://api.twitch.tv/kraken/streams/"+channel)
};