- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Map.delete() function in JavaScript
The delete() function of Map object accepts a string representing the key of an element of a map and deletes from the current Map object. This function returns true if the specified key exists in the map object else it returns false.
Syntax
Its Syntax is as follows
mapVar.delete()
Example
<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>
Output
Size of the map object: 3
Example
<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>
Output
true Size of the map object: 3 false Size of the map object: 3
Advertisements