I have below JSON object from which I want to fetch only certain values on my dev console log using javascript. I tried but below code but I don't know how to loop through array of array. Can anyone please suggest how can i achieve this.
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 trying to write JavaScript function that outputs the total number of subjects, each subject with marks, and average marks in the browser dev tools console in format given below.
Subjects: 3
- maths (90)
- english (80)
- physics (70)
Average: 80
The code should work for ANY JSON object with the same structure so don't want to use hard coded keys (eg. maths,physics)