JavaScript Map clear() Method Last Updated : 11 Jul, 2025 Suggest changes Share 3 Likes Like Report JavaScript Map.clear() method is used for the removal of all the elements from a map and making it empty. It removes all the [key, value] from the map. No arguments are required to be sent as parameters to the Map.clear() method and it returns an undefined return value.Syntax:mapObj.clear()Parameters:No parameters are required in the Map.clear() method.Return Value:Map.clear() method has an undefined return type.Examples of the above method are provided below.Example 1: In this example, a map object "myMap" has been created with a single [key, value] pair and the Map.clear() method is used to remove the [key, value] pair from "myMap". myMap.size() is used to check the number of [key, value] pairs belonging to the map object. javascript // creating a map object let myMap = new Map(); // Adding [key, value] pair to the map myMap.set(0, 'geeksforgeeks'); // displaying the number of // [key, value] pairs the map has console.log(myMap.size); // removing the [key, value] pairs of // the map using Map.clear() method myMap.clear(); // displaying the number of // [key, value] pairs the map has console.log(myMap.size); Output:10Example 2: In this example, a map object "myMap" has been created with a three [key, value] pairs and the Map.clear() method is used to remove all the [key, value] pairs from "myMap". myMap.size() is used to check the number of [key, value] pairs belonging to the map object. javascript // creating a map object let myMap = new Map(); // Adding [key, value] pair to the map myMap.set(0, 'geeksforgeeks'); myMap.set(1, 'is an online portal'); myMap.set(2, 'for geeks'); // displaying the number of // [key, value] pairs the map has console.log(myMap.size); // removing the [key, value] pairs // of the map using Map.clear() method myMap.clear(); // displaying the number of // [key, value] pairs the map has console.log(myMap.size); OUTPUT :30Applications:Map.clear() Method is used to remove all the [key, value] pairs of a map.Exceptions:If the variable is not of the Map type then the Map.entries() operation throws a TypeError.Supported Browsers:Chrome 38 Edge 12 Firefox 19 Opera 25 Safari 8 Create Quiz S Shubrodeep Banerjee Follow 3 Article Tags : Misc JavaScript Web Technologies javascript-map JavaScript-Methods +1 More Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like