How to print an object in JavaScript?

To print an object in JavaScript, do this: JSON.stringify(object).

Here's how you do it:

const object = { Hello: 'World!' };
const printedObject = JSON.stringify(object);

// {"Hello":"World!"}
console.log(printedObject);

You can also print a nicely formatted version:

const object = { Hello: 'World!' };
const printedObject = JSON.stringify(object, null, 2);

// {
//   "Hello": "World!"
// }
console.log(printedObject);