Dictionary
Dictionaries are key-value pairs used for easy lookups. They are also called associative arrays as each entry into the dictionary is a key with an associated value. In this lesson, we look at how to implement dictionaries in JavaScript, how to handle duplicate keys, and how to implement lookups and deletes.
Introduction
Dictionary is a data structure that consists of key-value pairs. It's a data structure where a key is associated with a value. Hence, they are also called associative arrays. Dictionaries provide lookups on their keys.
Let's go through a quick visualization:
Duplicates in Dictionary
We are not going to handle duplicates in our dictionary. Most implementations of associative arrays don't support duplicates as it is mostly thought of as a 1:1 relationship between a key and a value instead of a 1:N relationship. However, if you are in a situation where you need to associate duplicate values to a key, it's not that difficult to implement either.