I'm trying to grab class code property value from the object inside each array belonging to "class". (I'm aware my data is convoluted).
This is my student array:
student = [
{"class":[{
"code":"PSJ001",
"professor":"McHale",
"description":"course description"}]
},
{"class":[{
"code":"ENG303",
"professor":"Dench",
"description":"course description"}]
},
{"class":[{
"code":"SCI003",
"professor":"Biju",
"description":"course description"}]
}
]
What I'm trying to get is...
['PSJ001','ENG303','SCI003']
This is what I have...
let classCodes = [];
for (const i in student) {
classCodes = classCodes.concat(student[i].map(obj => {
return obj.code;
}));
}
What am I doing wrong here? (written in jsx)
studentsdoesn't exist.