I have a json like :
var data = [
{
"country":"Andorra",
"code":"AD",
"state":[
{
"state_code":"AD1",
"state_description":"aaAndorra1"
},
{
"state_code":"AD2",
"state_description":"aaAndorra2"
}
]
}
]
I would like to loop though the state property and get the state_code value
This is how I'm doing it :
for (var key in data) {
if (data.hasOwnProperty(key)) {
if(data[key].state.state_code === "AD1"){
console.log(data[key].state.state_description);
}
}
I'm getting undefined.
Any help please?
Thanks