I have the following json array:
var champions = [{
"1":{
"name":"Aatrox",
"role1":"Top",
"role2":"Jungle"},
"2":{
"name":"Ahri",
"role1":"Middle"},
"3":{"
name":"Akali",
"role1":"Middle",
"role2":"Top"
}
}];
and I trying to loop through this array with a code snippet I found:
$(document).ready(function(){
var x = 1;
for(var i = 0; i < champions.length; i++) {
console.log(champions[i][x].name);
x++;
}
});
But it only gives me "Aatrox" and stops as champions.length
is 1.
How can I loop through the array for all names?