The classic way to iterate over an object is to use a for .. in
loop.
for (prop in obj) {
val = obj[prop];
}
One possible side-effect of this technique is that you are not guaranteed to iterate over the properties in any particular order. If you know the property names ahead of time, you could create an array of property names and iterate.
Since your objects are nested, you will need to nest two for .. in
loops to iterate thoroughly:
for (prop in obj) {
nested_obj = obj[prop];
for (nested_prop in nested_obj) {
nested_val = nested_obj[nested_prop];
}
}
To get an array of all of the property names, you can build the array like this:
props = [];
for (prop in obj) {
props.push(prop);
nested_obj = obj[prop];
for (nested_prop in nested_obj) {
props.push(nested_prop);
nested_val = nested_obj[nested_prop];
}
}