EN
TypeScript - print object in console
0
points
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}