Open In App

Lodash _.isEmpty() Method

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:

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.




// Defining Lodash variable
const _ = require('lodash');
let val = null;
 
// Checking for Empty Value
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.




// Defining Lodash variable
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.




const _ = require('lodash');
 
let val1 = true;
let val2 = false;
 
// Checking for Empty Value
console.log("The Value is Empty :" + _.isEmpty(val1))
console.log("The Value is Empty :" + _.isEmpty(val2))

Output:

The Value is Empty : true

Article Tags :