I am trying to sum up a col1, col2, and col3 in my JSON using Jquery and not sure how to go about doing it using the .each loop. Another problem is col1, and col2, and col3 are dynamic so the names will be changing.
This is my JSON string:
var data = [
{
"Country": "Spain",
"Year": "2012",
"col1": "100.75",
"col2": "500",
"col3": "200"
},
{
"Country": "Spain",
"Year": "2013",
"col1": "200",
"col2": "500",
"col3": "300"
},
{
"Country": "France",
"Year": "2011",
"col1": "100",
"col2": "100",
"col3": "300"
},
{
"Country": "France",
"Year": "2012",
"col1": "100",
"col2": "100",
"col3": "300"
},
{
"Country": "France",
"Year": "2013",
"col1": "100",
"col2": "200",
"col3": "300"
}
]
I want two results that would look something like this:
1) Totals per country
Spain 300.75, 1000, 500
France 300, 400, 900
2) Grand total:
["col1", 600.75],
["col2", 1400],
["col3", 1400]
Thanks Cheers