EN
JavaScript - print array of objects in console
0 points
In this article, we would like to show you how to print an array of objects in a console working with JavaScript.
To print array of objects in the console, we need to use JSON.stringify()
method. For prettier printing, we can specify additional arguments replacer (e.g. null
) and spacer (e.g. 4
).
xxxxxxxxxx
1
const array = [
2
{ id: 1, value: 'a' },
3
{ id: 2, value: 'b' },
4
{ id: 3, value: 'c' },
5
];
6
7
console.log(JSON.stringify(array)); // prints array of objects
8
9
console.log(JSON.stringify(array, null, 4)); // pretty printing