Chartjs-"Cannot read property 'xyz' of undefined": How to use map or foreach on numeric json?

0👍

Changing

var labels = jsonfile.data.final_rank_1.players.forEach((player) => {
        return player.username;
    });
    var data = jsonfile.data.final_rank_1.players.forEach((player) => {
        return player.wins;
    });

to

var labels = jsonfile.data[0].final_rank_1.players.map(function(player) {
        return player.username;
    });
    var data = jsonfile.data[0].final_rank_1.players.map(function(player) {
        return player.wins;
    });

resolved my issue. Knowing what an object is and what an array is, is really helpful.

Leave a comment