ES6 - Map Method forEach



This function executes the specified function once per each Map entry.

Syntax

myMap.forEach(callback[, thisArg])             

Parameters

  • callback − Function to execute for each element.

  • thisArg − Value to use as this when executing callback.

Return Value

Undefined.

Example

function userdetails(key,value) { 
   console.log("m[" + key + "] = " + value); 
}  
var myMap = new Map(); 
myMap.set("id", "admin"); 
myMap.set("pass", "admin@123"); 
myMap.forEach(userdetails);  

Output

m[admin] = id 
m[admin@123] = pass  
Advertisements