The JSON:
[{"id":"1","user":"001","answer":"1,1,3,2,2,1,3,2"},
{"id":"2","user":"002","answer":"2,3,3,2,1,1,3,2"},
{"id":"3","user":"003","answer":"3,5,3,5,3,1,3,2"}]
The JavaScript:
jQuery.ajax({
url: "file.json",
type: "POST",
dataType: "json",
async: false,
success: function (data) {
var arr = [];
for (i = 0; i < data.length; i++) {
arr.push(data[i].answer);
}
console.log(arr);
});
What I'm trying to do is make an average of each value from the 3 answers, which in case will give these 8 averages:
2,3,3,3,2,1,3,2
["123","123456","123456789"]is that you're adding strings, so they add like characters next to each other. To add them mathematically as values, you need to convert them to numbers first.