Alright, so, I have this one JSON file
{
"status": "success",
"message": {
"affenpinscher": [],
"african": [],
"airedale": [],
"corgi": [
"cardigan"
],
"akita": [],
"appenzeller": [],
"basenji": [],
"beagle": [],
"bluetick": [],
"borzoi": [],
"bouvier": [],
"boxer": [],
"brabancon": [],
"briard": [],
"bulldog": [
"boston",
"french"
]
}
}
I need to loop through the list and check if the array of the breed is empty or not.
I've worked with JSON files in the past, but these sort of lists are usually inside some form of Arraylist, which allows me to simply loop through it, but I'm not really sure what I am supposed to do in this scenario.
Is there a way to select all the "children" of message.
This is what I have so far.
$.getJSON("https://dog.ceo/api/breeds/list/all", function (resp) {
var doglist = $('#doglist');
$.each(resp.message, function(dog) {
var dog1 = resp.message;
doglist.append('<li>' + dog + '</li>')
var subdog = Object.keys(dog1).length;
console.log(subdog);
});
});
I'm probably not being clear enough.
In my code snippet, there is a
var subdog = Object.keys(dog1).length;
this returns 15, as expected.
what I need is to do something like
var subdog = Object.keys(dog1.bulldog).length;
and have it return 2
but it needs to be done automatically for all breeds.
Basically loop through the list