D3.js count() method

With the help of d3.count() method, we can get the count of valid values in the specified iterable data structure.
Syntax:
d3.count(iterable[, accessor])
Return value: It returns the count of valid values.
Note: To execute the below examples you have to install the d3 library by using the command prompt for the following command.
npm install d3
Example 1: In this example, we can see that by using d3.count() method, we are able to get the count of valid values in the specified iterables.
Javascript
// Defining d3 contrib variableconst d3 = require('d3');Â
data = [    { name: "ABC", amount: "34.0", date: "11/12/2015" },    { name: "DEF", amount: "120.11", date: "11/12/2015" },    { name: "MNO", amount: "12.01", date: "01/04/2016" },    { name: "ABC", amount: "34.05", date: "01/04/2016" }]Â
let gfg = d3.count(data, d => d.amount);console.log(gfg); |
Output:
4
Example 2:
Javascript
// Defining d3 contrib variableconst d3 = require('d3');Â
data = [    { name: "ABC", amount: "34.0", age: 20 },    { name: "DEF", amount: "120.11", age: NaN },    { name: "MNO", amount: "12.01", age: 23 },    { name: "DEF", amount: "34.05", age: 24 }]Â
let gfg = d3.count(data, d => d.age);console.log(gfg); |
Output :
3
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!



