JavaScript Map clear() method

The JavaScript map clear() method eliminates all the elements from a Map object.

Syntax:

mapObj.clear()

Example:

<!DOCTYPE html>
<html>
<body>
<script>
var hello=new Map();
hello.set("GOOD MORNING");
hello.set("GOOD AFTERNOON");
hello.set("GOOD EVENING");
hello.set("GOOD NIGHT");
document.writeln("Number of elements: "+ hello.size+"<br>");
hello.clear();
document.writeln("Number of elements: "+hello.size);
</script>
</body>
</html>