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.
Practical example
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).
// ONLINE-RUNNER:browser;
const array = [
{ id: 1, value: 'a' },
{ id: 2, value: 'b' },
{ id: 3, value: 'c' },
];
console.log(JSON.stringify(array)); // prints array of objects
console.log(JSON.stringify(array, null, 4)); // pretty printing