console.countReset()

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.countReset()console.count() で使われたカウンターをリセットします。

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

構文

js
countReset();
countReset(label);

引数

label 省略可

文字列です。指定した場合、 countReset() はそのラベルに対するカウントを 0 にリセットします。省略した場合は、 countReset() は default のカウンターを 0 にリセットします。

返値

なし (undefined)。

例えば、次のようなコードがあったとします。

js
let user = "";

function greet() {
  console.count();
  return `hi ${user}`;
}

user = "bob";
greet();
user = "alice";
greet();
greet();
console.count();
console.countReset();

コンソールへの出力は、次のようになります。

"default: 1"
"default: 2"
"default: 3"
"default: 4"
"default: 0"

console.counterReset() の呼び出しによって default のカウンターが 0 にリセットされたことに注意してください。

変数 userlabel 引数として、最初の count() の呼び出しには文字列 "bob" を、 2 回目の呼び出しには文字列 "alice" を渡してみます。

js
let user = "";

function greet() {
  console.count(user);
  return `hi ${user}`;
}

user = "bob";
greet();
user = "alice";
greet();
greet();
console.countReset("bob");
console.count("alice");

以下のように出力されます。

"bob: 1"
"alice: 1"
"alice: 2"
"bob: 0"
"alice: 3"

"bob" のカウンターをリセットしたとき他のカウンターに影響を与えません。 "alice" のカウンターは変更されません。

仕様書

Specification
Console
# countreset

ブラウザーの互換性

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
countReset() static method

Legend

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

Full support
Full support