Node.js console.count() Method
Last Updated :
26 Jun, 2020
Improve
The console.count() method is an inbuilt application programming interface of the console module which is used to count label passed to it as a parameter, by maintaining an internal counter for that specific label.
Syntax:
javascript
Output:
javascript
Output:
console.count(label)Parameters: This method has one parameter as mentioned above and described below:
- label: It is an optional parameter specifies the label to be counted. Default value is "default".
// Node.js program to demonstrate the
// console.count() Method
// Accessing console module
const console = require('console');
// Calling console.count()
console.count("a");
console.count("b");
console.count("a");
console.count("a");
console.count("a");
console.count("b");
console.count("b");
console.count("b");
a: 1 b: 1 a: 2 a: 3 a: 4 b: 2 b: 3 b: 4Example 2:
// Node.js program to demonstrate the
// console.count() Method
// Accessing console module
const console = require('console');
// Calling console.count() method
// with no parameter to count
// default label
console.count();
console.count("a");
console.count("b");
console.count("a");
console.count("a");
console.count();
console.count();
console.count();
console.count("b");
default: 1 a: 1 b: 1 a: 2 a: 3 default: 2 default: 3 default: 4 b: 2Note: The above program will compile and run by using the
node filename.js
command.
Reference: https://nodejs.org/api/console.html#console_console_count_label