Tip - Better logging

web
Back

Use JSON.stringify method with third param(space).

// JSON.stringify(value, replacer, space)
JSON.stringify(user, null, 3);

Example

const user = {
firstName: "John",
lastName: "Doe",
address: {
firstLine: "AVC Road",
secondLine: "Baner Road",
state: "Maharastra",
},
};
console.log("User:\n", JSON.stringify(user, null, 2));

This will look like -

Thanks.

MIT © Mohan Dere.
-