このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

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 ⁨2015年7月⁩.

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

ブラウザーの互換性

関連情報