I have a JSON object that contains countries and data values. I need to add up the values of each country and compute their average. Here is the JSON object:
var arraySeries = [{"country":"United States","data":2},
{"country":"Venezuela","data":0},
{"country":"Singapore","data":3},
{"country":"United States","data":0},
{"country":"Germany","data":2},
{"country":"United States","data":2},
{"country":"Canada","data":2},
{"country":"Germany","data":-4}];
Here is the expected result:
var newArraySeries = [{"country":"United States","data":[1.33333]},
{"country":"Venezuela","data":[0]},
{"country":"Singapore","data":[3]},
{"country":"Canada","data":[2]},
{"country":"Germany","data":[-1]}];
The data in newArraySeries should be in an array format because I will be using it in my Highchart map. I have searched online but couldn't find any articles on this specific issue. I would really appreciate your help with this.