Open In App

Lodash _.isEmpty() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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




// 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.

javascript




// 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.

javascript




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


Last Updated : 24 Nov, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads