Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get the array values from Array?

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.

enter image description here

[
   {
      "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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[
   {
      "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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading