How to get the array values from JSON. I’m trying to pass it on highchart drilldown data[{}] and need to get the desired outcome in able to display the name and it’s total. Right now, I’m only getting these values 0,1,2,3,4,5,6,7,8,9,10 in my chart.
[
{
"course_code":"BSEE",
"total":1
},
{
"course_code":"BSIT",
"total":3
},
{
"course_code":"BSME",
"total":0
},
{
"course_code":"BSOA-LT",
"total":0
},
{
"course_code":"DICT",
"total":0
},
{
"course_code":"DOMT",
"total":0
}
]
This is my desire outcome
[
{
"BSEE",
1
},
{
"BSIT",
3
},
{
"BSME",
0
},
{
"BSOA-LT",
0
},
{
"DICT",
0
},
{
"DOMT",
0
}
]
>Solution :
Array.map approach
const data = [
{ course_code: "BSEE", total: 1 },
{ course_code: "BSIT", total: 3 },
{ course_code: "BSME", total: 0 },
{ course_code: "BSOA-LT", total: 0 },
{ course_code: "DICT", total: 0 },
{ course_code: "DOMT", total: 0 },
];
const output = data.map(({ course_code, total }) => [course_code, total]);
console.log(output);
