CodesJava

Easy learning with example program codes

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>

Output:

Number of elements: 4
Number of elements: 0
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status