Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NodeJS Tutorial
  • NodeJS Exercises
  • NodeJS Assert
  • NodeJS Buffer
  • NodeJS Console
  • NodeJS Crypto
  • NodeJS DNS
  • NodeJS File System
  • NodeJS Globals
  • NodeJS HTTP
  • NodeJS HTTP2
  • NodeJS OS
  • NodeJS Path
  • NodeJS Process
  • NodeJS Query String
  • NodeJS Stream
  • NodeJS String Decoder
  • NodeJS Timers
  • NodeJS URL
  • NodeJS Interview Questions
  • NodeJS Questions
  • Web Technology
Open In App
Next Article:
Node.js console.countReset() Method
Next article icon

Node.js console.count() Method

Last Updated : 26 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

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:

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”.

Return Value: This method outputs the count of this function called with the specified label to the stdout.

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

Example 1:




// 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");
 
 

Output:

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

Example 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");
 
 

Output:

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

Note: 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



Next Article
Node.js console.countReset() Method

G

gekcho
Improve
Article Tags :
  • Node.js
  • Web Technologies
  • Node.js-console-module
  • Node.js-Methods

Similar Reads

  • Node.js console.assert() Method
    The console.assert() method is an inbuilt application programming interface of the console module which is used to assert value passed to it as a parameter, i.e. it checks whether the value is true or not, and prints an error message, if provided and failed to assert the value. Syntax: console.asser
    2 min read
  • Node.js console.clear() Method
    The console.clear() method is used to clear the stdout, when stdout is a TTY (Teletype) i.e. terminal it will attempt to clear the TTY. When stdout is not a TTY, this method does nothing. The console.clear() will work differently across different operating systems and terminal types. For Linux opera
    1 min read
  • Node.js console.count() Method
    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: console.count(label) Parameters: This method has one parameter as mentioned a
    2 min read
  • Node.js console.countReset() Method
    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 b
    2 min read
  • Node.js console.debug() Method
    The console.debug() method is an inbuilt application programming interface of the console module which is used to print messages to stdout in a newline. Similar to the console.log() method. Syntax: console.debug(data, args); Parameters: This method has two parameters as mentioned above and described
    2 min read
  • Node.js console.dir() Method
    The console.dir() method is used to get the list of object properties of a specified object. These object properties also have child objects, from which you can inspect for further information. Syntax: console.dir( object ) Parameters: This method accepts single parameter which holds the object elem
    1 min read
  • Node.js console.error() Function
    The console.error() function from the console class of Node.js is used to display an error message on the console. It prints to stderr with a newline. Syntax: console.error([data][, ...args]) Parameter: This function can contain multiple parameters. The first parameter is used for the primary messag
    1 min read
  • Node.js console.info() Method
    The console.info() method is an inbuilt application programming interface of the console module which is used to print messages to stdout in a newline. It is similar to the console.log() method. Syntax: console.info(data, args); Parameters: This method has two parameters as mentioned above and descr
    2 min read
  • Node.js console.timeLog() Method
    The console.timeLog() method is an inbuilt function in Nodejs that is used to display the time for each execution. This function is proved to be effective when used in a loop. Syntax: console.log([label][, ...data]) Parameters: This function accepts two or more parameters. Return Value: This method
    1 min read
  • Node.js console.time() Method
    The console.time() method is the console class of Node.js. It is used to starts a timer that is used to compute the time taken by a piece of code or function. The method console.timeEnd() is used to stop the timer and output the elapsed time in milliseconds to stdout. The timer can be accurate to th
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences