Here is the JSON structure that I am working with:
var data = [
{
"country":"Andorra",
"code":"AD",
"state":[
{
"state_code":"AD1",
"state_description":"aaAndorra1"
},
{
"state_code":"AD2",
"state_description":"aaAndorra2"
}
]
}
]
My goal is to iterate over the 'state' property and retrieve the value of the 'state_code'
This is my current approach :
for (var key in data) {
if (data.hasOwnProperty(key)) {
if(data[key].state.state_code === "AD1"){
console.log(data[key].state.state_description);
}
}
However, I'm getting an undefined result.
Any suggestions or assistance would be greatly appreciated.
Thank you!