CodesJava

Easy learning with example program codes

JavaScript Map set() method

The JavaScript map set() method adds a new or modifies the already existing key-value pairs to Map object.

Syntax:

mapObj.set(key,value)

Parameters:
key: It represents the key of newly added map object.
value: It represents the value of newly added map object.

Return:
Updated map object.

Example:

<!DOCTYPE html>
<html>
<body>
<script>  
var map=new Map();  
map.set('a',"GOOD MORNING");
map.set('b',"GOOD AFTERNOON");
map.set('c',"GOOD EVENING");  
map.set('d',"GOOD NIGHT");  
var itr= map.keys();  
for(i=0;i<map.size;i++){
   document.writeln(itr.next().value+"<br>"); 
}
</script>  
</body>
</html>

Output:

a
b
c
d
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status