Sometimes, we want to add dictionaries in JavaScript like Python.
In this article, we’ll look at how to add dictionaries in JavaScript like Python.
How to add dictionaries in JavaScript like Python?
To add dictionaries in JavaScript like Python, we can create an object.
For instance, we write
const statesDictionary = {
CT: ["alex", "harry"],
AK: ["liza", "alex"],
TX: ["fred", "harry"],
};
console.log(statesDictionary.AK[0]);
to create the statesDictionary
object that has some keys and values inside.
Then we can access the object’s property values by writing
statesDictionary.AK[0]
Conclusion
To add dictionaries in JavaScript like Python, we can create an object.