I wrote this code:
$(document).ready(function() {
var streamNames = [
"ESL_SC2",
"OgamingSC2",
"nl_kripp",
"nl_kripp",
"freecodecamp",
"storbeck"
];
for (var i = 0; i < streamNames.length; i++) {
$.getJSON(
"https://api.twitch.tv/kraken/streams/" +
streamNames[i] +
"?client_id=.......",
function(data) {
if (data.stream == null) {
$("#status" + [i]).text("Offline");
} else {
$("#status" + [i]).text("Online");
console.log(i)
}
;
There are 2 problems occurring here.
1.The JSON data comes randomly and not in the order of the array.
2.i is always 6 (last count) in the for expression.
Anyone could help me out figure out why this is happening?