Sunday, 21 October 2018

JavaScript: Map.prototype.values(): Get all the values in Map

Map.prototype.values()
This method return all the values in the map in insertion order.

Example
var values = countriesMap.values();

for(value of values){
  console.log(value);
}

Find the below working application.

HelloWorld.js
var countriesMap = new Map();

countriesMap.set("Bahrain", "Manama");
countriesMap.set("Cameroon", "Yaounde");
countriesMap.set("Norway", "Oslo");
countriesMap.set("India", "New Delhi");

var values = countriesMap.values();

for(value of values){
  console.log(value);
}


Output
Manama
Yaounde
Oslo
New Delhi




Previous                                                 Next                                                 Home

No comments:

Post a Comment