Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

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:

0

Notes

The method changes the Map itself. Every variable that refers to this Map sees an empty collection too.

See also

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.

Thanks for reading!

Donate to the site — we work hard for you.