Collect.js | count() Function
Last Updated :
05 Jun, 2020
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
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
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
Reference: https://collect.js.org/api/count.html
Share your thoughts in the comments
Please Login to comment...