JavaScript中的Map.forEach()函数
forEach()Map对象的功能返回相应Map对象的迭代器,使用该迭代器可以检索映射的键值对。
语法
它的语法如下
mapVar.forEach()
示例
<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>输出结果
Java JavaFX HBase Neo4j