Collect.js make() Function Last Updated : 26 Nov, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 function takes only one parameter i.e. the user collection which is the collection defined by the user. Return Value: This function returns the new collection object. Example 1: Filename-index.js JavaScript // 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 ]Example 2: Filename-index.js JavaScript // Requiring module const collect = require('collect.js') // User defined collection var myCollection = ['Monday', 'Tuesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] // Function definition function make(items = []) { return new this.constructor(items); } // Creating collection object const collection = collect(myCollection); // Make Function call console.log(make(collection)) Run the index.js file using the following command: node index.jsOutput: Collection { items: [ 'Monday', 'Tuesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ] } Reference: https://collect.js.org/api/make.html Comment More infoAdvertise with us Next Article Collect.js | when() Function G gouravhammad Follow Improve Article Tags : Technical Scripter JavaScript Web Technologies Collect.js Similar Reads Collect.js tap() Function Collect.js is a fluent and convenient wrapper for working with arrays and objects. The tap() function accepts the collection as a parameter and without affecting the collection it allows the user to tap into the collection at a specific point and do anything with the item. Installation:Â Install the 1 min read Collect.js | when() Function The when() function is used to callback if the first argument in the given proves to be true. In JavaScript, the array is first converted to a collection and then the function is applied to the collection.Syntax:Â data.when(conditional ,rule) Parameters:Â This function accept two parameters as mentio 1 min read Collect.js where() Function The where() function is used to filter the collection by a given key or value contained within the given array. In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax: data.where('key') Parameters: This function accepts a single paramet 2 min read Collect.js | zip() Function The zip() function is used to combine the values of given array with the values of original collection at a given index. In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax:Â data.zip(value) Parameters:Â This function accept a single 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 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 Like