filmov
tv
Nested JSON Objects | How to Iterate over the JSON Object and its Children Objects in Javascript

Показать описание
Code :
{
"Animals":{
"cat": {
"humanFriendly": [
"Yes"
]
},
"tiger": {
"humanFriendly": [
"No"
]
},
"chettah": {
"humanFriendly": [
"No"
]
},
"lion": {
"humanFriendly": [
"No"
]
},
"jaguar": {
"humanFriendly": [
"No"
]
},
"dog": {
"humanFriendly": [
"Yes",
"No"
]
}
}
}
Program :
var typeOfAnimals = jsonObject["Animals"]
value = "lion"
function animalsJson(json,value){
for (index in json){
var obj = json[index]
if(value == index){
break;
}
}
}
animalsJson(typeOfAnimals,value)
Next Steps :
---------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------
Must Watch Playlists
---------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------
#nestedJSONobjects
#readJSONObjects
#javascript
{
"Animals":{
"cat": {
"humanFriendly": [
"Yes"
]
},
"tiger": {
"humanFriendly": [
"No"
]
},
"chettah": {
"humanFriendly": [
"No"
]
},
"lion": {
"humanFriendly": [
"No"
]
},
"jaguar": {
"humanFriendly": [
"No"
]
},
"dog": {
"humanFriendly": [
"Yes",
"No"
]
}
}
}
Program :
var typeOfAnimals = jsonObject["Animals"]
value = "lion"
function animalsJson(json,value){
for (index in json){
var obj = json[index]
if(value == index){
break;
}
}
}
animalsJson(typeOfAnimals,value)
Next Steps :
---------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------
Must Watch Playlists
---------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------
#nestedJSONobjects
#readJSONObjects
#javascript
Комментарии