Collect.js isEmpty() Method

The isEmpty() method is used to check the given collection is empty or not and returns the corresponding boolean value.
Syntax:
collect(array).isEmpty()
Parameters: The collect() method takes one argument that is converted into the collection and then isEmpty() method is applied on it.
Return Value: This method checks the given collection is empty or not and returns the corresponding boolean value.
Below example illustrate the isEmpty() method in collect.js:
Example 1:
const collect = require('collect.js'); Â Â let arr = []; Â Â const collection = collect(arr); Â Â const isemp = collection.isEmpty(); Â Â console.log(isemp); |
Output:
true
Example 2:
const collect = require('collect.js'); Â Â const collection = collect({}); Â Â const isemp1 = collection.isEmpty(); Â Â console.log(isemp1); Â Â const collection1 = collect([10, 20, 30]); Â Â const isemp2 = collection1.isEmpty(); Â Â console.log(isemp2); |
Output:
true false
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!



