Given the JSON object below, I am looking to extract specific values using JavaScript in my browser's dev console. However, I am not sure how to loop through an array of arrays. Can anyone provide guidance on achieving this task?
var infoJSON;
for(key in myClass) {
infoJSON = myClass[key];
console.log(infoJSON);
}
var myClass= {
"Subjects":"3",
"Subject":{
"maths":{
"subject_id":"1",
"subject_level":"easy",
"marks":"90"
},
"english":{
"subject_id":"2",
"subject_level":"medium",
"marks":"80"
},
"physics":{
"subject_id":"3",
"subject_level":"tough",
"marks":"70"
}
},
"Average": "80"
};
I am working on a JavaScript function that will display the total number of subjects, each subject with its marks, and the average marks in the browser console as shown below.
Subjects: 3
- maths (90)
- english (80)
- physics (70)
Average: 80
The goal is for the code to be dynamic and work with any JSON object following the same structure without hardcoding keys such as maths or physics.