JavaScript 中的 Map.delete() 函数
javascriptjsonweb developmentfront end technology更新于 2024/10/5 6:04:17
Map 对象的 delete() 函数接受表示映射元素键的字符串,并从当前 Map 对象中删除。如果指定的键存在于映射对象中,则此函数返回 true,否则返回 false。
语法
其语法如下
mapVar.delete()
示例
<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');
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 示例</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
相关文章
有用资源
javascript 参考教程 - 该教程包含有关 javascript 的更多信息:https://www.cainiaomax.com/javascript/

