- 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
Clearing a Dictionary using Javascript
We'll implement a clear() function that simply clears the contents of the container. For example,
Example
clear() { this.container = {} }
You can test this using −
Example
const myMap = new MyMap(); myMap.put("key1", "value1"); myMap.put("key2", "value2"); myMap.display(); myMap.clear(); myMap.display();
Output
This will give the output −
{ key1: 'value1', key2: 'value2' }
You can use the clear method in the same way in ES6 maps as well. For example,
Example
const myMap = new Map([ ["key1", "value1"], ["key2", "value2"] ]); console.log(myMap) myMap.clear(); console.log(myMap)
Output
This will give the output −
Map { 'key1' => 'value1', 'key2' => 'value2' } Map {}
- Related Articles
- Clearing the set using Javascript
- Python - Clearing list as dictionary value
- Clearing the elements of the PriorityQueue using Javascript
- Clearing localStorage in JavaScript?
- Creating Dictionary using Javascript
- Clearing the elements of a Stack in Javascript
- Remove elements from a Dictionary using Javascript
- Search Element in a Dictionary using Javascript
- Clearing the elements of the Queue in Javascript
- Loop through a Dictionary in Javascript
- Plot a bar using matplotlib using a dictionary
- Clearing items in a nested MongoDB array?
- How to convert Javascript dictionary to Python dictionary?
- Add elements to a Dictionary in Javascript
- How to create a Dictionary using C#?

Advertisements