- 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
The Dictionary Class in Javascript
Here is the complete implementation of MyMap class −
Example
class MyMap { constructor() { this.container = {}; } display() { console.log(this.container); } hasKey(key) { return key in this.container; } put(key, value) { this.container[key] = value; } delete(key) { if (this.hasKey(key)) { delete this.container[key]; return true; } return false; } get(key) { return this.hasKey(key) ? this.container[key] : undefined; } keys() { return Object.keys(this.container); } values() { let values = []; for (let key in this.container) { values.push(this.container[key]); } return values; } clear() { this.container = {}; } forEach(callback) { for (let prop in this.container) { // Call the callback as: callback(key, value) callback(prop, this.container[prop]); } } }
- Related Articles
- Dictionary Class in C#
- Importance of a Dictionary class in Java?
- Dictionary Data Structure in Javascript
- How to convert Javascript dictionary to Python dictionary?
- Creating Dictionary using Javascript
- Loop through a Dictionary in Javascript
- The Stack Class in Javascript
- The Queue Class in Javascript
- The PriorityQueue Class in Javascript
- The Set Class in Javascript
- The HashTable Class in Javascript
- Add elements to a Dictionary in Javascript
- Search Element in a Dictionary using Javascript
- Clearing a Dictionary using Javascript
- The Linked List Class in Javascript

Advertisements