JavaScript – Map forEach()
JavaScript Map.forEach() is used to execute a given function for each of the key-value pair in this Map.
Syntax
The syntax to call forEach() method on a Map map1
is
map1.forEach (function(value, key) { //code })
ADVERTISEMENT
Examples
In the following example, we take a Map with keys 'a'
, 'b'
, and 'c'
. We shall loop through these key-value pairs using forEach() method.
index.html
Conclusion
In this JavaScript Tutorial, we learned how to use Map.forEach() method in JavaScript, with examples.