VOOZH about

URL: https://www.geeksforgeeks.org/javascript/check-if-a-set-is-empty-in-javascript/

⇱ Check if a Set is Empty in JavaScript? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Check if a Set is Empty in JavaScript?

Last Updated : 23 Jul, 2025

These are the following ways to check whether the given set is empty or not:

1. Using size property - Mostly used

The size property is used to get the size of the set. if it returns 0 then the set will be empty else it has some elements.


Output
Empty set
Not empty set


2. Using Lodash _.isEmpty() Method

The Lodash is JavaScript library, that provide the _.isEmpty() Method, that checks whether the given set is empty or not and returns the boolean value.

Note: The function can take any value as a parameter to check, it is not limited to set only.

Output:

Empty set

3. Using Array.from() Method and length Property

The Array.from() method returns an array from any object with a length property. so it helps us to access the length property so that we can check its emptiness. This method does not alt the original object.


Output
Not empty set
Comment