JavaScript 中的 Map.forEach() 函数

javascripthtmlweb developmentfront end technology

Map 对象的 forEach() 函数返回相应 Map 对象的迭代器,您可以使用它来检索映射的键值对。

语法

其语法如下

mapVar.forEach()

示例

<html>
<head>
   <title>JavaScript 示例</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>

输出

Java
JavaFX
HBase
Neo4j

相关文章