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:
- 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: In this example, the _.isEmpty() method returns true as null is an empty value itself which does not hold any value.
javascript
const _ = require( 'lodash' );
let val = null ;
console.log( "The Value is Empty :" + _.isEmpty(val))
|
Output:
The Value is Empty : true
Example 2: In this example, the _.isEmpty() method returns true as the length of the array is zero.
javascript
const _ = require( 'lodash' );
let val = []
console.log( "The Value is Empty :" + _.isEmpty(val))
|
Output:
The Value is Empty : true
Example 3: In this example, the _.isEmpty() method returns true for both of the Boolean values.
javascript
const _ = require( 'lodash' );
let val1 = true ;
let val2 = false ;
console.log( "The Value is Empty :" + _.isEmpty(val1))
console.log( "The Value is Empty :" + _.isEmpty(val2))
|
Output:
The Value is Empty : true
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks 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!
Last Updated :
24 Nov, 2023
Like Article
Save Article