When I recently started playing around the epynomous Wikipedia Viewer challenge on Free Code Camp, traversing the wikipedia API tree was an important first step. While there are many techniques, I decided to go for a recursive function approach. Pay attention however as Javascript creates a stack for each recursive call...
The way this works is straightforward:
- For each JSON object determine whether it is a defined (bang bang!!) object.
- If it is an object, recursively call the function to traverse it.
- If it is not an object (example: array, string, value), then it must be a leaf node!
Take the Wikipedia API JSON tree as an example which looks like this:
The traverse function will iterate through each object, but for the sake of this example, scanning through the first object of the Pages object will look like this:
9 Comments
branding advertising agency
mobile app consultant
top branding
user interface design agencies
logo creator company
agency web design
top UX companies
top UX designers