Open In App

Collect.js count() Function

Last Updated : 15 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The count() function is used to count the number of collections in the element.

Syntax: 

data.count()

Parameters:

This function does not accept any parameter

Return Value:

Returns the count of the element in that collection.

Example 1:Below examples illustrate the count() function in collect.js 

JavaScript
// It is used to import collect.js library
const collect = require('collect.js');

const num = [0 , 1 , 2 , 3 , 4, 5 , 6, 7, 8, 9]; 
const data = collect(num);
const total = data.count();

console.log('Total number of elements are:', {total});

Output:

Total number of elements are: { total: 10 }

Example 2:

JavaScript
// It is used to import collect.js library
const collect = require('collect.js');

const collection = collect([1, 2, 3, 4]);
const x = collection.count();

console.log(`Total number of elements are : ${x}`);

Output:

Total number of elements are : 4


Similar Reads