console.group()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

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

メモ: この機能はウェブワーカー内で利用可能です。

構文

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
# group

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
group() static method

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報