How to prettify a JavaScript object

Assuming you have a POJO (Plain Old JavaScript Object):

var object = {
    key: 'value'
    // properties...

JSON.stringify can be used to prettify the output:

    JSON.stringify(object, null, 4);

If you’re using Node.js and your object has circular references, you’ll want to use something like util.inspect:

var util = require('util');
    util.inspect(object, { depth: null });

Please support this site and join our Discord!