While working with the Oracle Field Service plugin in Javascript, I have observed that many developers use ππ¨π§π¬π¨π₯π.π₯π¨π (ππππ.π¬ππ«π’π§π π’ππ²()) and struggle with the structure of objects on the console. The ππππ.π¬ππ«π’π§π π’ππ²() method provides an option to properly indent the output on the console for debugging, which can be very helpful for understanding the structure of the objects.
// JSON.stringify
const person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
console.log(JSON.stringify(person));
/*
output
{"firstName":"John","lastName":"Doe","age":50,"eyeColor":"blue"}
*/
// Indent the output with one space
console.log(JSON.stringify(person,null,"\t"));
/*
output
{
"firstName": "John",
"lastName": "Doe",
"age": 50,
"eyeColor": "blue"
}
*/
I will be posting tricks I have been using in my journey.
So follow me on LinkedIn.
Top comments (0)