Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
12+
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Salesforce
Microsoft
SAP
July 27, 2023
Basic console.log will not go through long and complex objects, and may decide to just print [Object] instead.
Two of the suitable ways to print the object with nested properties are exemplified below:
1.
util.inspect(object[, options]) const util = require('util'), const obj = {} // some complex object console.log(util.inspect(obj, {depth: null})); //{ depth: null } instructs util.inspect to open everything until it gets to a circular reference //There are other options also available, such as showHidden, colors, maxStringLength, maxArrayLength, sorted, etc. //Documentation: https://nodejs.org/api/util.html#utilinspectobject-options
2.
JSON.stringify(value, replacer, space) const obj = {} console.log(JSON.stringify(obj, null, "\t")); // "/t" would format the output with a tab in each line of property output //Documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify