Check if a Set is Empty in JavaScript? Last Updated : 11 Nov, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report These are the following ways to check whether the given set is empty or not:1. Using size property - Mostly usedThe 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. JavaScript let s = new Set(); if (s.size === 0) console.log("Empty set") else console.log("Not empty set") // Let us add an item to check for a non-empty set s.add(1); if (s.size === 0) console.log("Empty set") else console.log("Not empty set") OutputEmpty set Not empty set 2. Using Lodash _.isEmpty() MethodThe 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. JavaScript const _ = require("lodash"); let s = new Set(); if (_.isEmpty(s) === true) { console.log("Empty set") } else { console.log("Not empty set") } Output:Empty set3. Using Array.from() Method and length PropertyThe 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. JavaScript let s = new Set(); s.add(1); if(Array.from(s).length === 0) { console.log("Empty set") } else {console.log("Not empty set") } OutputNot empty set Comment More infoAdvertise with us Next Article Check if a Map is Empty in JavaScript? M meetahaloyx4 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Set Similar Reads Check if a Map is Empty in JavaScript? These are the following ways to check whether the given map is empty or not:1. Using size property - Mostly Usedyou can check if a Map is empty by using its size property. The size property returns the number of key-value pairs in the Map. If the size is 0, the Map is empty. JavaScriptconst m = new 2 min read Check if an array is empty or not in JavaScript These are the following ways to check whether the given array is empty or not:1. The length Property - mostly usedThe length property can be used to get the length of the given array if it returns 0 then the length of the array is 0 means the given array is empty else the array have the elements.Jav 1 min read Check if an Object is Empty in TypeScript In TypeScript, determining whether an object is empty involves checking if the object has any properties. This can be achieved through various built-in methods and loops. In this article, we will explore three different approaches to check if an object is empty in TypeScript.Table of ContentUsing Ob 2 min read How to Check an Object is Empty using JavaScript? These are the following ways that can be used to Check an Object is Empty using JavaScript: 1. Using Object.keys() Method - Mostly usedThe Object.keys() method returns an array that contains the property names of an object. If the length of array is 0, then object is empty.JavaScriptlet obj = {}; if 2 min read How to Check if an Object is Empty in TypeScript ? In TypeScript, it's common to encounter scenarios where you need to determine if an object is empty or not. An empty object typically means it contains no properties or all its properties are either undefined or null. Below are the methods to check if an object is empty or not in TypeScript: Table o 3 min read How to check if a value is object-like in JavaScript ? In JavaScript, objects are a collection of related data. It is also a container for name-value pairs. In JavaScript, we can check the type of value in many ways. Basically, we check if a value is object-like using typeof, instanceof, constructor, and Object.prototype.toString.call(k). All of the ope 4 min read Like