Collect.js | count() Function

The count() function is used to count the number of collections in the element. In JavaScript, the array is first converted to a collection and then the function is applied to the collection.

Syntax: 

data.count()

Parameters: This function does not accept any parameter
Return Value:  Returns the count of the element in that collection.
 

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

Javascript



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Total number of elements are: { total: 10 }

Example 2:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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}`);

chevron_right


Output:

Total number of elements are : 4

Reference: https://collect.js.org/api/count.html

full-stack-img

My Personal Notes arrow_drop_up

Check this out nerdboinet

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.