I am passing an array through a for loop in jQuery. However, order of the array elements is random after each pass. It does not follow the original element position while displaying the array in html. The order is important as I want to match them with another array output. Here is the code:
$(document).ready(function(){
var streams = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
var name = [];
var cLogo =[];
for (var j = 0; j < streams.length; j++) {
$.getJSON("https://api.twitch.tv/kraken/users/" + streams[j]+"?client_id=z4tearbiduwua797pngirp8texyqik",function(c){
name[j] = c.display_name;
cLogo[j] = c.logo;
if(cLogo[j]==null){
cLogo[i]="http://www.freeiconspng.com/uploads/no-image-icon-32.png";
}
$('#name').append('<div><p>'+name[j]+'</p></div>');
$('#logo').append("<div><img src='"+cLogo[j]+"'></div>");
});
};
});