For each member in the second generation, find the descendants. The descendants of the second generation are the third generation. Listing 14 shows how to navigate an object tree using a recursive function. The result of the code in Listing 14 when you run it in a Web browser is as follows. In the previous section you have learned how you can navigate an object tree.
Navigation works from the root towards the objects in the next generations.
The same principle is used when you search for a particular object in the tree. You begin the search from the root, and you continue until you find a match. Sometimes, once you find a match, you can return the object without continuing the navigation until the last object. For example, the code in Listing 15 builds an object tree like the above and then searches for a dog called bulbul. When found, the name and the color of the dog is displayed, and the function raises the flag found .