Collect.js Introduction Last Updated : 13 Dec, 2021 Comments Improve Suggest changes Like Article Like Report 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 functions that help in working with data much easier.It also helps the programmers to write more concise code and easier to maintain the JavaScript code.It is also compatible with Laravel. Installation: We can install collect.js by following two methods. Method 1: We can install it using npm. Make sure that you have Node.js and npm installed. npm install collect-js Method 2: We can also use it through CDN Links. Go to the https://cdnjs.com/libraries/collect.js and add the following CDN link inside <script> tag. <script src="https://cdnjs.cloudflare.com/ajax/libs/collect.js/4.29.3/collect.min.js" integrity="sha512eHrXl+YqedGIdIKP5YOueP0z7RfRgmo7R1d8pTvEOhikZIFpD54dXbwp9os9z4hVHVHZeRHw0qfF93lDsQDQA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> Lets's see an example of how collect.js works. Example: In this example, we will see how to create new collection instance using Collect.js make() Function. index.js // Requiring module const collect = require('collect.js') // User defined collection var myCollection = [1,2,3,4,5] function make(items = []) { return new this.constructor(items); } // Creating collection object const collection = collect(myCollection); // Printing collection console.log(collection.all()); // Make Function call console.log(make([1,2,3])) Run the index.js file using the following command: node index.jsOutput: [ 1, 2, 3, 4, 5 ] [ 1, 2, 3 ] Comment More infoAdvertise with us Next Article Collect.js | all() Method K kartik Follow Improve Article Tags : JavaScript Web Technologies Collect.js Similar Reads Collect.js Collect.js is the javascript library for collecting data from tree-based structures. This library is used on JavaScript Array and Objects. Collect.js TutorialWhy Collect.js? It is a fluent and convenient wrapper for working with arrays and objects. It provides us with different functions that help i 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 | all() Method The all() method is used to return the underlying array or object represented by the collection. The JavaScript array is first transformed into a collection and then the function is applied to the collection. Syntax: collect(array).all() Parameters: The method does not accept any parameter. Return 1 min read Collect.js average() Method The average() method is used to return the average of all the items in a collection. This method is an alias of avg() method. Syntax: collect(array).average() Parameters: The collect() method takes one argument that is converted into the collection and then average() function is applied on it, which 1 min read Collect.js | avg() Method Collect.js is a fluent and convenient wrapper for working with arrays and objects. The JavaScript array is first transformed into a collection and then the function is applied to the collection. The avg() method returns the average of all the items in a collection. Installation: Collect.js can be in 2 min read Collect.js | collapse() Method Collect.js is a fluent and convenient wrapper for working with arrays and objects. The JavaScript array is first transformed into a collection and then the function is applied to the collection. The collapse() method convert collection of arrays into a single flat array. Installation: Collect.js can 2 min read Collect.js | combine() Method Collect.js is a fluent and convenient wrapper for working with arrays and objects. The JavaScript array is first transformed into a collection and then the function is applied to the collection.The combine() method combines two different arrays with keys-values. Installation:  Collect.js can be in 1 min read Collect.js concat() Method The concat() method is used to return the merged arrays or objects represented by the collection. The JavaScript array is first transformed into a collection and then the function is applied to the collection. Syntax: collect(array1).concat(array2) Parameters: The collect() method takes one argument 2 min read Collect.js contains() Method The contains() method is used to determines whether the collection contains a given item or not. If it contains the item then it returns true otherwise false. The JavaScript array is first transformed into a collection and then the function is applied to the collection. Syntax:  collect(array).cont 2 min read Collect.js countBy() Method The countBy() method is used to count the occurrence of values in the collection. This method counts the occurrence of every element. Syntax: collect(array).countBy() Parameters: The collect() method takes one argument that is converted into the collection and then countBy() method is applied on it. 1 min read Like