This
method calls the call back function for every <key, value> pair.
map.forEach(function(value, key) {
console.log(key + ' = ' + value);
});
Find
the below working application.
function printMap(map){ console.log("***************************"); console.log("Total elements in countriesMap are : " + map.size); map.forEach(function(value, key) { console.log(key + ' = ' + value); }); console.log("***************************"); } var countriesMap = new Map(); countriesMap.set("Bahrain", "Manama"); countriesMap.set("Cameroon", "Yaounde"); countriesMap.set("Norway", "Oslo"); countriesMap.set("India", "New Delhi"); countriesMap.set("Russia", "Moscow"); countriesMap.set("Spain", "Madrid"); printMap(countriesMap);
Output
***************************
Total
elements in countriesMap are : 6
Bahrain
= Manama
Cameroon
= Yaounde
Norway
= Oslo
India
= New Delhi
Russia
= Moscow
Spain
= Madrid
***************************
No comments:
Post a Comment