JavaScript Clearing a Map


Example

To remove all elements from a Map, use the .clear() method:

map.clear();

Example:

const map = new Map([[1, 2], [3, 4]]);
console.log(map.size); // 2
map.clear();
console.log(map.size); // 0
console.log(map.get(1)); // undefined