Ausgabe
So erhalten Sie die Array-Werte von JSON . Ich versuche, es an Highchart-Drilldown-Daten [{}] weiterzugeben, und muss das gewünschte Ergebnis erzielen, um den Namen und die Gesamtzahl anzuzeigen. Im Moment bekomme ich nur diese Werte 0,1,2,3,4,5,6,7,8,9,10 in meinem Diagramm.
[
{
"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
}
]
Das ist mein Wunschergebnis
[
{
"BSEE",
1
},
{
"BSIT",
3
},
{
"BSME",
0
},
{
"BSOA-LT",
0
},
{
"DICT",
0
},
{
"DOMT",
0
}
]
Lösung
Array.map
sich nähern
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);
Beantwortet von – Nitheesh
Antwort geprüft von – Candace Johnson (FixError Volunteer)