I need to transform an array of objects into another array of objects but transposed. This is the form highcharts accepts arrays.
I need to go from
var n0 = [{
"a": 1,
"b": 4
}, {
"a": 2,
"b": 6
}, {
"a": 3,
"b": 8
}]
to
var n1 = [{
"name": "a",
"data": [1, 2, 3]
}, {
"name": "b",
"data": [4, 6, 8]
}];
What about changing from
var input = [{
"date": "JAN",
"category": "abc",
"thevalue": 5
}, {
"date": "JAN",
"category": "xyz",
"thevalue": 4
}, {
"date": "FEB",
"category": "abc",
"thevalue": 9
}, {
"date": "FEB",
"category": "xyz",
"thevalue": 10
}]
To
var output = [{
"name": "abc",
"data": [5,9]
}, {
"name": "xyz",
"data": [4, 10]
}];
Can this be accomplished with the same functions? I've read two javascript books but somehow these puzzles are far above my abilities. I don't even know where to start learning. I guess I could reread the chapter about objects and arrays, the issue is those examples are very basic.
datein your expected output