このページはコミュニティーの尽力で英語から翻訳されました。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
console.group()
console.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");

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

コンソール出力に入れ子になっているメッセージのスクリーンショット。

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

仕様書

Specification
Console
# group

ブラウザーの互換性

関連情報