Check if a Map is Empty in JavaScript? Last Updated : 15 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. JavaScript const m = new Map(); if (m.size === 0) { console.log("Empty") } else { console.log("Not Empty") } OutputEmpty 2. Using for ... of LoopYou can use a for...of loop to attempt to iterate over the Map's entries. If the loop doesn't execute, the Map is empty. JavaScript const myMap = new Map(); let isEmpty = true; for (let [k, val] of myMap) { isEmpty = false; break; } if (isEmpty) { console.log("Empty") } else { console.log("Not Empty") } OutputEmpty 3. Using the keys() MethodThe keys() method of a Map returns an iterator for the keys in the Map. If the Map is empty, the iterator will not yield any values. JavaScript let mp = new Map(); let res = mp.keys().next().done; if (res) { console.log("Empty") } else { console.log("Not Empty") } OutputEmpty 4. Using entries() MethodSimilar to keys(), the entries() method of a Map returns an iterator for the key-value pairs in the Map. You can check whether the iterator has any entries. JavaScript let mp = new Map(); let res = mp.entries().next().value; if (res) { console.log("Not Empty") } else { console.log("Empty") } OutputEmpty 5. Using ._isEmpty() Lodash Method This ._isEmpty() Lodash Method is used to check whether the given data having any data type is empty or not and it return boolean value. if it is empty it return true else false. JavaScript let _ = require("lodash") let mp = new Map(); if (_.isEmpty(mp)) { console.log("Empty") } else { console.log("Not Empty") } Output:Empty Comment More infoAdvertise with us Next Article Check if an Object is Empty in TypeScript M meetahaloyx4 Follow Improve Article Tags : JavaScript Web Technologies javascript-map Similar Reads Check if a Set is Empty in JavaScript? 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. JavaScriptlet s = new Set(); if (s.size === 0) console.log("Empt 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 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 Check if an Array is Empty or not in TypeScript In TypeScript, while performing any operation on the array, it is quite important that there should be elements or data in the array, else no operation can be done. We can check whether the array contains the elements or not by using the below-listed methods: Table of Content Using length PropertyUs 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 Like