Saturday, 20 October 2018

JavaScript: Set.prototype.entries(): Get all the elements in the set

Set.prototype.entries()
This method returns an Iterator object that contains an array of [value, value] for each element in the Set.

HelloWorld.js
function printSetInfo(set){
  console.log("***********************************");
  console.log("Number Of Elements : " + set.size);
  
  var entries = countries.entries();
  
  /*key and value are same */
  for(var [key, value] of entries){
    console.log(key);
  }
  
  console.log("***********************************");
}

var countries =  new Set();

countries.add("India");
countries.add("Australia");
countries.add("Canada");
countries.add("Germany");

printSetInfo(countries);


Output

***********************************
Number Of Elements : 4
India
Australia
Canada
Germany
***********************************




Previous                                                 Next                                                 Home

No comments:

Post a Comment