Javascript Map clear()

Introduction

The Javascript Map clear() method removes all elements from a Map object.

It returns undefined.

myMap.clear();
var myMap = new Map();
console.log(myMap);//www.java 2 s  .  c om
myMap.set('bar', 'baz');
myMap.set(1, 'foo');

console.log(myMap);

myMap.size;       
console.log(myMap.size);// 2
console.log(myMap.has('bar')); // true

myMap.clear();

console.log(myMap.size);       // 0
console.log(myMap.has('bar'))  // false



PreviousNext

Related