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);
}
Source:stackexchange.com