I was wondering what the issue with the bottom loop is or if I'm going through the last json wrong somehow when I'm trying to log it into the console. The arrays are above the given code and the first two loops work fine. I'm trying to return goals but the reality is I want to find an efficient way to return all of the stats.
d3.json('https://statsapi.web.nhl.com/api/v1/teams', function(data) {
for (i=0; i < 31; i++) {
teamID.push(data.teams[i].id);
}
});
console.log(teamID);
// request roster json data from API and loop through roster to get all player IDS
// and append them to the playerList array
d3.json('https://statsapi.web.nhl.com/api/v1/teams/1/?expand=team.roster', function(data) {
for (i=0; i < data.teams[0].roster.roster.length; i++) {
playerList.push(data.teams[0].roster.roster[i].person.id);
}
});
console.log(playerList);
// request player stat json data from API and loop through all players to get all stat
// and append them to an array
var playerStats = [];
for (i = 0; i < playerList.length; i++) {
d3.json('https://statsapi.web.nhl.com/api/v1/people/' + playerList[i] + '/stats/?stats=statsSingleSeason&season=20172018', function(data) {
console.log(data.stats[0].splits[0].stat.goals);
});
// console.log(playerStats);
};