- 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
Dictionary Data Structure in Javascript
In computer science, an associative array, map, symbol table, or dictionary is an abstract data type composed of a collection of (key, value) pairs, such that each possible key appears at most once in the collection. Note that a dictionary is also known as a map.
The dictionary problem is a classic computer science problem: the task of designing a data structure that maintains a set of data during 'search', 'delete', and 'insert' operations. There are many different types of implementations of dictionaries.
- Hash Table implementation
- Tree-Based Implementation (Self-balancing and Unbalanced trees)
- List based implementation
When to use a Dictionary
Dictionaries are not a silver bullet and should not be used at every chance you get. They are useful in many scenarios, but you need to keep the following points in mind before deciding to use a dictionary to solve a problem.
- Inserts are generally slow, reads are faster than trees.
- Use these for fast lookups, for example, to cache data, index databases, symbol tables, etc.
- When the order of elements doesn't matter.
- When all element keys are unique.
Methods we'll implement
Dictionaries generally have a well-defined APIs. We're going to implement a very basic dictionary API as defined below −
- get(): Gets the element with the input key
- put(): Puts the key-value pair in the dictionary
- hasKey(): Checks if the key is present in the dictionary
- delete(): Removes the given key from the dictionary
- clear(): Removes all key-value pairs from the dictionary
- keys(): Returns all keys as an array
- values(): Returns all values as an array
- Related Articles
- Dictionary Operations in Data Structure
- Arrays Data Structure in Javascript
- Stack Data Structure in Javascript
- Queue Data Structure in Javascript
- Set Data Structure in Javascript
- Tree Data Structure in Javascript
- Graph Data Structure in Javascript
- Linked List Data Structure in Javascript
- Hash Table Data Structure in Javascript
- Rectangle Data in Data Structure
- Explain how series data structure in Python can be created using dictionary and explicit index values?
- Data Dictionary in DBMS
- Adding and searching for words in custom Data Structure in JavaScript
- Deaps in Data Structure
- Quadtrees in Data Structure
