console.group(label) & console.groupEnd(label)👇

Sometimes, there may be a scenario where we want to log values within a loop. The best thing to do will be to add a separator at the end of each loop to separate the values of each iteration, but that is still not efficient enough since there are no labels to describe the logs.

With console.group it becomes really simple to properly organize related data and represent each group with a definitive group label while logging to the console.

The methods take an optional argument — label which is the name of the group.

Although it’s not required to pass an argument to console.group() , still, we should do it in order to clarify what values are being grouped together.

We don't have to pass the group name to console.groupEnd() because it will always close the recently created group.

We can also create nested groups if we call console.group() inside an already created group. Here’s a quick example which will help us to understand it better.

console.group() and console.groupEnd()

Notes: Groups created by console.group(label) are initially opened, we can display the group as collapsed from the outset if we call console.groupCollapsed(label) . Here’s an example: