The Lodash _.isEmpty() Method Checks if the value is an empty object, collection, map, or set. Objects are considered empty if they have no own enumerable string keyed properties. Collections are considered empty if they have a 0 length. Similarly, maps and sets are considered empty if they have a 0 size.
Syntax:
_.isEmpty( value )
Parameters: This method accepts a single parameter as mentioned above and described below:
- value: This parameter holds the value that needs to be Checked for Empty value.
Return Value: This method returns a Boolean value(Returns true if the given value is an Empty value, else false).
Example 1: This method returns true when the value is null.
// Defining Lodash variable const _ = require('lodash'); // Checking for Empty Value console.log("The Value is Empty : " +_.isEmpty(null)); |
Output:
The Value is Empty : true
Example 2: This method returns true when an Array is empty.
// Defining Lodash variable const _ = require('lodash'); var val = [] // Checking for Empty Value console.log("The Value is Empty : " +_.isEmpty(val)); |
Output:
The Value is Empty : true
Example 3: This method returns true for Boolean value.
// Defining Lodash variable const _ = require('lodash'); var val = false; // Checking for Empty Value console.log("The Value is Empty : " +_.isEmpty(val)); |
Output:
The Value is Empty : true
Example 4: In this example, the method will return false.
// Defining Lodash variable const _ = require('lodash'); var val = { "a": 1 }; // Checking for Empty Value console.log("The Value is Empty : " +_.isEmpty(val)); |
Output:
The Value is Empty : false
Note: This will not work in normal JavaScript because it requires the lodash library to be installed.
Lodash library can be installed using npm install lodash.
Recommended Posts:
- Collect.js isEmpty() Method
- PHP | Ds\Collection isEmpty() Function
- PHP | Ds\Deque isEmpty() Function
- PHP | Ds\Vector isEmpty() Function
- PHP | SplDoublyLinkedList isEmpty() Function
- Underscore.js | _.isEmpty()
- Lodash _.method() Method
- Lodash _.sneq() Method
- Lodash _.toQuery() Method
- Lodash _.uniqWith() Method
- Lodash _.xorWith() Method
- Lodash | _.head() Method
- Lodash | _.remove() Method
- Lodash | _.pullAt() Method
- Lodash | _.pullAll() Method
- Lodash | _.pull() Method
- Lodash | _.nth() Method
- Lodash | _.takeRight() Method
- Lodash | _.take() Method
- Lodash | _.sortedLastIndex() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


