HTML DOM console.count()Method

Console 对象Console Object

Example

Logs the number of times count() has been called and outputs it to the console:

for (i = 0; i < 10; i++) { console.count(); }

Try it Yourself »

Definition and Usage

When console.count() is called, it writes a number (the call count) to the console.

The console.count() method can add a label.


Syntax

console.count(label)

Browser Support

The numbers in the table indicate the first browser version that fully supports the method.

Method
console.count() Yes Yes 30 Yes Yes

Parameter Description

Parameter Type Description
label String Optional. If specified, a label is output to the console, and the label is displayed before the call count.

More Examples

Example

Call console.count() twice and view the result:

console.count(); console.count();

Try it Yourself »

Example

Call console.count() twice with a label, and view the result:

console.count("Example"); console.count("Example"); console.count("Example2");

Try it Yourself »

Each time console.count() is called, if the label is the same, the corresponding count number increases by 1; if it is different, the count restarts.

Console 对象Console Object

Other Extensions