Collect.js tap() Function Last Updated : 12 Jan, 2021 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 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 Collect.js module using the following command: npm install --save collect.jsSyntax: collection.tap(callback)Parameters: This function takes only one parameter i.e. the callback function which executes as per user need. 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 = [2, 4, 3, 1, 5] // Function call var newCollection = collect(myCollection) .tap((collection) => { // Printing collection console.log(collection.all()); }) console.log(newCollection) Run the index.js file using the following command: node index.jsOutput: [ 2, 4, 3, 1, 5 ] Collection { items: [ 2, 4, 3, 1, 5 ] }Example 2: Filename-index.js JavaScript // Requiring module const collect = require('collect.js') // User defined collection var myCollection = [-1,2,0,25] // Sorting and displaying result collect(myCollection).sort().tap((collection) => { console.log(collection.all()); }) Run the index.js file using the following command: node index.jsOutput: [ -1, 0, 2, 25 ] Reference: https://collect.js.org/api/tap.html Comment More infoAdvertise with us Next Article Collect.js | push() Function G gouravhammad Follow Improve Article Tags : Technical Scripter JavaScript Web Technologies Collect.js Similar Reads 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 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 Collect.js whenNotEmpty() Function Collect.js is a fluent and convenient wrapper for working with arrays and objects. The whenNotEmpty() function executes the callback function when the collection is not empty. Installation: Install the Collect.js module using the following command: npm install --save collect.jsSyntax:  collection. 1 min read Collect.js count() Function 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 JavaScrip 1 min read 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 Like