Chartjs-ChartJS creating var takes each character and outputs undefined

1👍

This is because your response data is a string and a for..in over a string iterates the characters in the string.
If you’re expecting your json to be parsed into an array, you have to set the dataType in your ajax request to json, use JSON.parse or set the content type on your server to application/json.

dataType: 'json',
success: function(data) {
        console.log(data);
        var n = [];
        var s = [];

        for(var i in data) {
            n.push(data[i].name);
            s.push(data[i].score);
        }

Leave a comment