Saturday 20 October 2018

JavaScript: Set.prototype.forEach(callbackFn[, thisArg]): Calls the callback function for every element in the set

Set.prototype.forEach(callbackFn[, thisArg])
This method calls the callback function for every element in the set.

  set.forEach(function(ele){
    console.log(ele);
  });

HelloWorld.js
function printSetInfo(set){
  console.log("***********************************");
  console.log("Number Of Elements : " + set.size);
  
  set.forEach(function(ele){
    console.log(ele);
  });
  
  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