DEV Community

Omar Dulaimi
Omar Dulaimi

Posted on

Logging navigable trees in Javascript

To produce navigable trees from any Javascript object, use π—°π—Όπ—»π˜€π—Όπ—Ήπ—².𝗱𝗢𝗿. You will get an interactive list of all object properties.

One nice thing about this method is that it can handle DOM elements too. So instead of getting the original HTML elements, you get a JSON representation of the object, as you can see in the snap below how different the document object looks with π—°π—Όπ—»π˜€π—Όπ—Ήπ—².𝗱𝗢𝗿 as opposed to π—°π—Όπ—»π˜€π—Όπ—Ήπ—².𝗹𝗼𝗴.

It takes a second object parameter with these options:
1- π—±π—²π—½π˜π—΅ => set it to null if you want to cover all levels recursively.
2- π—°π—Όπ—Ήπ—Όπ—Ώπ˜€
3- π˜€π—΅π—Όπ˜„π—›π—Άπ—±π—±π—²π—» => shows non-enumerable keys and Symbols.

If you have an XML/HTML element, then use π—°π—Όπ—»π˜€π—Όπ—Ήπ—².π—±π—Άπ—Ώπ˜…π—Ίπ—Ή instead.

Note that you could also use 𝗱𝗢𝗿 and π—±π—Άπ—Ώπ˜…π—Ίπ—Ή directly without the need for the π—°π—Όπ—»π˜€π—Όπ—Ήπ—² object.

Follow for more tips :)

console.dir

Top comments (0)