I need to transform the following object:
"age": [
{
"Under 20": "14",
"Above 40": "1"
}
]
into this structure:
$scope data = {rows:[
{c: [
{v: "Under 20"},
{v: 14}
]},
{c: [
{v: "Above 40"},
{v: 1},
]}
}]
I attempted:
$.map(resp.age, (el, key) => {
arr.push({c: [{v: el}, {v: el}]});
});
Although I am familiar with using $.map
and arr.push
, I'm struggling to extract the key Under 20
along with its corresponding value 14
.
Is there a better way to achieve this task?