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