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:
xxxxxxxxxx
1
interface MyObject {
2
id: number;
3
name: string;
4
age: number;
5
}
6
7
const object: MyObject = { id: 2, name: 'Tom', age: 25 };
8
9
console.log(JSON.stringify(object, null, 4)); // beauty printing
10
console.log(JSON.stringify(object)); // compressed printing
Output:
xxxxxxxxxx
1
{
2
"id": 2,
3
"name": "Tom",
4
"age": 25
5
}
6
{"id":2,"name":"Tom","age":25}