![]() |
VOOZH | about |
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.js
Syntax:
collection.unlessEmpty(callback)
Parameters: This function takes only one parameter i.e. the callback function which executes if the collection is not empty.
Return Value: This function returns the new collection object.
Example 1: Filename-index.js
Run the index.js file using the following command:
node index.js
Output:
[ 1, 2, 3 ]
Example 2: Filename-index.js
Run the index.js file using the following command:
node index.js
Output:
[ ]
Reference: https://collect.js.org/api/unlessempty