I have an object with multiple objects, and need to create a loop for each key within each object.
I need the console to log something like this.
Iron
TIBC
carbon dioxide
Sodium
etc...
This is what I have tried so far
(function() {
var blood = {
"blood": {
"one": {
"iron": "Iron",
"tibc": "TIBC",
},
"two": {
"cd": "Carbon Dioxide",
"sodium": "Sodium",
"potassium": "Potassium",
"chloride": "Chloride",
},
"three": {
"cholesterol": "Cholesterol",
"dhdl": "Direct HDL",
},
"four": {
"rigg": "Rubella IgG",
"hbsag": "HBsAg",
"ahiv": "Anti-HIV 1+2",
"estrdiol": "Estradiol",
"fsh": "FSH",
}
}
}
for (var key in blood) {
if (blood.hasOwnProperty(key)) {
var newKey = blood[key]
for (var key in newKey) {
if (newKey.hasOwnProperty(key)) {
//do stuff
console.log(newKey[key])
}
}
}
}
})
letinstead ofvar.keytry changing it to a different name()at the very end!)