console.group()

console.group() メソッドは、ウェブコンソールのログに、新たなインライングループを作成します。console.groupEnd() を呼び出すまで、以降のすべての出力を 1 段階字下げします。

注: この機能は Web Worker 内で利用可能です

構文

js
group();
group(label);

引数

label 省略可

グループ用のラベルです。

返値

なし (undefined)。

ネストされたグループを使用して関連したメッセージを視覚的に結びつけることで、出力を整理する手助けができます。新しいネストのブロックを作成するには、console.group() を呼び出します。console.groupCollapsed() メソッドは類似していますが、新しいブロックが折りたたまれており、表示するには、展開ボタンをクリックする必要があります。

現在のグループを終了するには、console.groupEnd() を呼び出してください。例えば、以下のようなコードがあったとします。

js
console.log("This is the outer level");
console.group();
console.log("Level 2");
console.group();
console.log("Level 3");
console.warn("More of level 3");
console.groupEnd();
console.log("Back to level 2");
console.groupEnd();
console.log("Back to the outer level");

出力は以下のようになります。

A screenshot of messages nested in the console output.

詳しくは、console のドキュメントで コンソールでのグループの使用をご覧ください。

仕様書

Specification
Console Standard
# group

ブラウザーの互換性

BCD tables only load in the browser

関連情報