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