Sometimes, we want to create a hash or dictionary object in JavaScript.
In this article, we’ll look at how to create a hash or dictionary object in JavaScript.
How to create a hash or dictionary object in JavaScript?
To create a hash or dictionary object in JavaScript, we can create a plain object.
For instance, we write
const a = {};
a["key1"] = "value1";
a["key2"] = "value2";
to create object a
.
Then we add properties to it with
a["key1"] = "value1";
a["key2"] = "value2";
The property names are in the square brackets and the values are after the =
sign.
Conclusion
To create a hash or dictionary object in JavaScript, we can create a plain object.