DEV Community

Cover image for 📂Beyond the log - Console.group()
Iain Freestone
Iain Freestone

Posted on • Updated on • Originally published at iainfreestone.com

📂Beyond the log - Console.group()

console.group() can be useful if you are outputting lots of nested data, allowing you to open and close groups of data when needed. Making it much quicker to find what you are looking for.

It can be used alongside other console methods such as table(), log() etc.

let books = [
  { title: "Best Book Ever", authors: [{ name: "Joe Bloggs", age: "21" }] },
  {
    title: "Learn to draw",
    authors: [{ name: "Jane Doe", age: "37" }, { name: "Bill Day", age: "18" }]
  }
];

console.group("Books");
books.map(book => {
  console.log("Title:", book.title);
  console.group("Authors");
  console.table(book.authors);
  console.groupEnd();
});
Enter fullscreen mode Exit fullscreen mode

If you enjoyed this little snippet you can follow me on Twitter where I regularly post bite size tips relating to HTML, CSS and JavaScript.

Top comments (1)

Collapse
 
gottz profile image
Jan-Stefan Janetzky

what i don't like about groups:
any code besides your own can interfer.

if anything does a console.log while you are inside such a group, it will be removed from your sight