Map.keys() function in JavaScript


The keys() function of Map object is similar to entries but, it returns an iterator object containing the keys of a map object.

Syntax

Its Syntax is as follows

Map.keys()

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');
      var it = mapVar.keys();
      for(i=0; i<mapVar.size; i++) {
         document.write(it.next().value);
         document.write(" <p> ");
      }
   </script>
</body>
</html>

Output

1
2
3
4

Updated on: 25-Jun-2020

29 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements