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

📂Beyond the log - Console.group()

iainfreestone profile image Iain Freestone Updated on ・1 min read

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();
});

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.

Discussion

markdown guide
 

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