I can't for the life of me select this correctly? I may have the for loop wrong so please advice if that is the case:
function(data, callback){
data.champNames = {};
for(var c in data.champId){
val = data.champId[c];
var surl = 'https://global.api.pvp.net/api/lol/static-data/euw/v1.2/champion/'+ [val] + '?api_key=' + api_key;
request(surl, function(err, response, body){
if(!err && response.statusCode == 200){
var json = JSON.parse(body);
//data.champNames.push(json[val].name);
console.log(json);
} else {
console.log('Error in Champ Name');
}
})
console.log(val);
} console.log(data);
}
The data.champNames.push(json[val].name) will not work, JSON is returned as the below in console:
{ id: 1, key: 'Annie', name: 'Annie', title: 'the Dark Child' }
{ id: 76,
key: 'Nidalee',
name: 'Nidalee',
title: 'the Bestial Huntress' }
{ id: 15,
key: 'Sivir',
name: 'Sivir',
title: 'the Battle Mistress' }
{ id: 103,
key: 'Ahri',
name: 'Ahri',
title: 'the Nine-Tailed Fox' }
Data is a global variable used within an async waterfall.
ChampId is already in an array and is returned as:
champId: [ 22, 236, 76, 21, 36, 133, 24, 103, 81, 79, 45, 15, 1, 0 ],