Map.delete() 方法在 JavaScript
Map 对象的 delete() 方法接收一个代表 map 元素键的字符串,并从当前的 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP