Collect.js whenEmpty() Function Last Updated : 13 Jun, 2022 Comments Improve Suggest changes Like Article Like Report 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.whenEmpty(callback)Parameters: This function takes only one parameter i.e. the callback function which executes if the collection is empty. 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 = [] // Creating collection object const collection = collect(myCollection); // Callback execution since collection object is empty collection.whenEmpty(item => item.push('Greetings')); // Printing collection console.log(collection.all()); Run the index.js file using the following command: node index.jsOutput: [ 'Greetings' ]Example 2: Filename-index.js JavaScript // Requiring module const collect = require('collect.js') // User defined collection var myCollection = ['One', 'Two', 'Three'] // Creating collection object const collection = collect(myCollection); // No callback execution since collection is not empty collection.whenEmpty((item) => { item.push('Four') item.push('Five') item.push('Six') }); // Printing collection console.log(collection.all()); Run the index.js file using the following command: node index.jsOutput: [ 'One', 'Two', 'Three'] Reference: https://collect.js.org/api/whenEmpty.html Comment More infoAdvertise with us Next Article Collect.js whenEmpty() Function gouravhammad Follow Improve Article Tags : Technical Scripter JavaScript Web Technologies Collect.js Similar Reads 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 | 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 unlessEmpty() Function Collect.js is a fluent and convenient wrapper for working with arrays and objects. The unlessEmpty() 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.u 1 min read Collect.js unlessNotEmpty() Function Collect.js is a fluent and convenient wrapper for working with arrays and objects. The unlessNotEmpty() 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.un 1 min read Collect.js whereIn() Function The whereIn() 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.whereIn('key') Parameters: This function accepts a single par 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 | whereNotBetween() Function The whereNotBetween()function is used to filter an input which do not lie in a specified range. In JavaScript, the array is first converted to a collection and then the function is applied to the collection.Syntax: data.whereNotBetween(key, [range]); Parameters: This function accepts two parameters 2 min read 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 | 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 Like