Every
map has a ‘size’ property, it returns the number of <key, value> pairs in
the map.
var countries = [["Russia", "Moscow"], ["Spain", "Madrid"]]; var countriesMap = new Map(countries); countriesMap.set("Bahrain", "Manama"); countriesMap.set("Cameroon", "Yaounde"); countriesMap.set("Norway", "Oslo"); countriesMap.set("India", "New Delhi"); for (var [country, capital] of countriesMap) { console.log(country + ' : ' + capital); } console.log("Total elements in countriesMap are : " + countriesMap.size);
Output
Russia
: Moscow
Spain
: Madrid
Bahrain
: Manama
Cameroon
: Yaounde
Norway
: Oslo
India
: New Delhi
Total
elements in countriesMap are : 6
No comments:
Post a Comment