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 parameterReturn 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 Comment More infoAdvertise with us Next Article Collect.js count() Function akhilsharma870 Follow Improve Article Tags : JavaScript Web Technologies Collect.js Similar Reads Collect.js first() Function The first() function gives the first value of the collection. It returns the first value or the first method returns the first element in the collection that passes a given condition. Syntax: data.first(e)Parameters: This function accepts a single parameter as mentioned above and described below:e: 1 min read Collect.js | flip() function The flip() function swaps the key with its corresponding value. In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax: data.flip() Parameters: This function does not accept any parameter. Return Value:  Returns by flipping the collect 1 min read Collect.js | forPage() Function The forPage() function is used to return the value which is present at a particular page, this function take the page number as an argument and then returns the collection. In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax: data.f 1 min read Collect.js Introduction Collect.js is a JavaScript library for collecting data from tree-based structures. This library is used on JavaScript Array and Objects. Features: Some of the important features of Collect.js are: It is a fluent and convenient wrapper for working with arrays and objects.It provides us with different 2 min read Collect.js | push() Function The push() function is used to add a new value to the end of the collection.  In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax: data.push(value) Parameters: This function accepts a single parameter as mentioned above and describe 1 min read Collect.js make() Function Collect.js is a fluent and convenient wrapper for working with arrays and objects. The make() function creates a new collection instance. Installation: Install the Collect.js module using the following command: npm install --save collect.jsSyntax:  collection.make(user collection)Parameters: This f 2 min read Collect.js | chunk() Function The chunk() function breaks the collection to many small collections of the given size.  In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax: data.chunk(x) Parameter:  This function accepts a single parameter as mentioned above and 2 min read Collect.js | random() function The random() function as the name suggest it returns any random value from the collection. In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax: data.random(number) Parameters: This function accept a single parameter as mentioned abo 1 min read PHP count() Function The count() function in PHP is used to count the number of elements in an array or the countable properties of an object. The function returns an integer value representing the number of items present.Syntax:count($array, mode)In this syntax:$array (mandatory): Refers to the array, whose elements ar 3 min read Collect.js whenEmpty() Function Collect.js is a fluent and convenient wrapper for working with arrays and objects. The whenEmpty() function executes the callback function when the collection is empty. Installation: Install the Collect.js module using the following command: npm install --save collect.jsSyntax:  collection.whenEmp 1 min read Like