Member-only story
Are there dictionaries in JavaScript?
No, as of now JavaScript does not include a native Dictionary data type. So what is equivalent to a dictionary?
Objects in JavaScript are equivalent to a dictionary.
Objects in JavaScript are quite flexible and can be used to create key-value pairs. These objects are quite similar to dictionaries.
Dictionaries are commonly used as each value stored has a unique key, and through these keys, their respective values can be accessed. This allows a lot of fleixibility while reading and storing data.
Create a dictionary
var dict = {}; //dict is the name of the object
Add a value
dict[key] = value
Delete a value
delete dict.key;
Access a value
var value = dict.key;
Attributes of dictionaries
Dictionaries are unordered, meaning that any time you loop through a dictionary , you will go through every key. But you are not guaranteed to get them in any particular order.