The usual console log can often print “[Object object]”, which is not useful.
Some convenient ways to see the entire object in logs are below.
Using the %o format specifier, which means “formatted as an object”:
Using the dir function:
The “dir” in console.dir() comes from “directory”, as in a directory of all the properties of the object. This always outputs a full hierarchical representation of the object.
Another way is to fully serialize the object into a JSON string:
This is very useful especially in the context of loggers, so if logger is an instance of a logging object (such as a Winston logger), then we can log a complete JSON object using: