JavaScript中的Map.clear()函数
clear()Map对象的功能从当前Map对象中删除所有元素。
语法
其语法如下
mapVar.clear()
示例
<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 map = mapVar.clear();
document.write("Size of the map object: "+mapVar.size);
</script>
</body>
</html>输出结果
Size of the map object: 0
示例
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var mapVar = new Map();
mapVar.set('1', 'Raju');
mapVar.set('2', 'Ram');
mapVar.set('3', 'Rahim');
mapVar.set('4', 'Robert');
document.write("Size of the map: "+mapVar.size);
var map = mapVar.clear();
document.write("<br>");
document.write("Size of the map after clearing its contents using clear() function: "+mapVar.size);
</script>
</body>
</html>输出结果
Size of the map: 4 Size of the map after clearing its contents using clear() function: 0
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短