Languages
[Edit]
EN

TypeScript - print object in console

0 points
Created by:
Paluskitten
356

In this article, we would like to show you how to print object in the console in TypeScript.

Quick solution:

interface MyObject {
  id: number;
  name: string;
  age: number;
}

const object: MyObject = { id: 2, name: 'Tom', age: 25 };

console.log(JSON.stringify(object, null, 4)); // beauty printing
console.log(JSON.stringify(object));          // compressed printing

Output:

{
    "id": 2,      
    "name": "Tom",
    "age": 25     
}
{"id":2,"name":"Tom","age":25}
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join