I got some troubles with arrays. I'm trying to build my own lol-site. I'm using node, async, express and ejs. When i call an URL i got a response (see below). The problem is that i don't really know how to fetch data i want. It would be easier, but this JSON is not always looking the same way.
{
"playerStatSummaries": [
{
"playerStatSummaryType": "CAP5x5",
"aggregatedStats": {
"totalNeutralMinionsKilled": 2042,
"totalMinionKills": 4317,
"totalChampionKills": 350,
"totalAssists": 417,
"totalTurretsKilled": 36
},
"modifyDate": 1453247261000,
"wins": 20
},
{
"playerStatSummaryType": "OdinUnranked",
"aggregatedStats": {
"averageNodeCaptureAssist": 1,
"maxNodeNeutralizeAssist": 5,
"maxChampionsKilled": 24,
"totalChampionKills": 4577,
"totalAssists": 4732,
"averageChampionsKilled": 8,
"averageNodeCapture": 5,
"averageNumDeaths": 6,
"maxNodeNeutralize": 10,
"averageNodeNeutralize": 3,
"averageTeamObjective": 1,
"averageTotalPlayerScore": 985,
"maxNodeCapture": 12,
"maxObjectivePlayerScore": 1226,
"averageNodeNeutralizeAssist": 2,
"averageAssists": 7,
"maxTotalPlayerScore": 2218,
"maxAssists": 29,
"maxCombatPlayerScore": 1132,
"averageCombatPlayerScore": 406,
"maxNodeCaptureAssist": 4,
"totalNodeCapture": 2166,
"totalNodeNeutralize": 1455,
"maxTeamObjective": 2,
"averageObjectivePlayerScore": 573
},
"modifyDate": 1468740801000,
"wins": 256
},
{
"playerStatSummaryType": "Unranked",
"aggregatedStats": {
"totalNeutralMinionsKilled": 65540,
"totalMinionKills": 392799,
"totalChampionKills": 28967,
"totalAssists": 31347,
"totalTurretsKilled": 3007
},
"modifyDate": 1480708148000,
"wins": 1964
},
{
"playerStatSummaryType": "RankedSolo5x5",
"aggregatedStats": {
"totalNeutralMinionsKilled": 5304,
"totalMinionKills": 17234,
"totalChampionKills": 935,
"totalAssists": 2276,
"totalTurretsKilled": 125
},
"losses": 96,
"modifyDate": 1480808818000,
"wins": 101
}
],
"summonerId": 'xxxxx'
}
I was trying to use but it's not working the way i want it:
var json = JSON.parse(body);
for(var m=0; m<json['playerStatSummaries'].length; m++){
s.push(json['playerStatSummaries'][m].playerStatSummaryType, json['playerStatSummaries'][m].wins);
};
And it's giving me back:
[ 'CAP5x5',
20,
'OdinUnranked',
256,
'Unranked',
1964,
'RankedSolo5x5',
101 ]
I would like to get Unranked and 1964 from the first array. I don't know what to do with it. I would like to fecth (from first array) playerStatSummaryType Unranked and wins.
Basic