Map.prototype.clear
Removes all entries from a Map.
Available since: ES2015
Syntax
map.clear()Return value
undefinedReturns nothing.
Examples
Clearing a collection:
const cache = new Map([['a', 1], ['b', 2]]);
cache.clear();
console.log(cache.size);Output:
0Notes
The method changes the Map itself. Every variable that refers to this Map sees an empty collection too.
See also
- Map.prototype.delete — Removes the entry for a key.
- Map.prototype.size — The number of entries in a Map.
In the tutorial
- Map and Set — The Map and Set collections in JavaScript: a dictionary with keys of any type and a set of unique values.