Map.forEach() function in JavaScript


The forEach() function of Map object returns an iterator of the corresponding Map object and using this you can retrieve the key Value pairs of the map.

Syntax

Its Syntax is as follows

mapVar.forEach()

Example

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var mapVar = new Map();
      mapVar.set('1', 'Java');
      mapVar.set('2', 'JavaFX');
      mapVar.set('3', 'HBase');
      mapVar.set('4', 'Neo4j');
      function show(values) {
         document.write(values);
         document.write("<br>");
      }
      mapVar.forEach(show);
   </script>
</body>
</html>

Output

Java
JavaFX
HBase
Neo4j

Updated on: 25-Jun-2020

57 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements