Favorites

JavaScript Map.prototype.clear() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Map.prototype.clear()
JavaScript Map Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The clear() method removes every entry from a Map.

Description

The clear() method removes all entries from the map, leaving size at 0.

It changes the map in place, so every variable that refers to the same map sees it empty. If other code might still need the old entries, create a new Map instead of clearing the shared one.

Clearing is useful for caches that should be reset, such as when a user logs out or the data they were built from changes. Set has a clear() method that works the same way.

Syntax

map.clear()

Return Value

None (undefined).

Example

const m = new Map([['a', 1], ['b', 2]]);
m.clear();
console.log(m.size);

Browser Support

The following information will show you the current browser support for the Map.prototype.clear() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee