Skip to content
Related Articles
Open in App
Not now

Related Articles

Node.js console.countReset() Method

Improve Article
Save Article
  • Last Updated : 13 Jul, 2020
Improve Article
Save Article

The console.countReset() method is an inbuilt application programming interface of the console module which is used to reset the count for the specific label passed to it as a parameter.

Syntax:

console.countReset( label );

Parameters: This method has one parameter as mentioned above and described below:

  • label: It is an optional parameter that specifies the label whose counter to be reset. Default value is “default”.

Return Value: This method does not provide any output but reset the counter for the specified label.

Below examples illustrate the use of console.countReset() method in Node.js:

Example 1:




// Node.js program to demonstrate the 
// console.countReset() method
  
// Accessing console module
const console = require('console');
   
// Calling console.count() method 
console.count("a");
console.count("b");
console.count("a");
console.count("a");
console.count("a");
console.count("b");
   
// Resetting counter
console.countReset("a");
console.countReset("b");
   
console.count("a");
console.count("b");


Output:

a: 1
b: 1
a: 2
a: 3
a: 4
b: 2
a: 1
b: 1

Example 2:




// Node.js program to demonstrate the 
// console.countReset() 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();
  
// Resetting counter
console.countReset();
console.countReset("a");
console.countReset("b");
  
console.count();
console.count("a");
console.count("b");


Output:

default: 1
a: 1
b: 1
a: 2
a: 3
default: 2
default: 3
default: 1
a: 1
b: 1

Note: The above program will compile and run by using the node filename.js command.

Reference: https://nodejs.org/api/console.html#console_console_countreset_label


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!