JavaScript中的Map.delete()函数
delete()Map对象的功能接受代表映射元素键的字符串,并从当前Map对象中删除。如果指定的键存在于映射对象中,则此函数返回true,否则返回false。
语法
其语法如下
mapVar.delete()
示例
<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.delete('4');
document.write("Size of the map object: "+mapVar.size);
</script>
</body>
</html>输出结果
Size of the map object: 3
示例
<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.delete('4');
document.write(map);
document.write("<br>");
document.write("Size of the map object: "+mapVar.size);
document.write("<br>");
var map = mapVar.delete('5');
document.write(map);
document.write("<br>");
document.write("Size of the map object: "+mapVar.size);
</script>
</body>
</html>输出结果
true Size of the map object: 3 false Size of the map object: 3
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短