Iain Freestone

📂Beyond the log - Console.group()

May 25, 2020

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