JavaScript Answers

How to add dictionaries in JavaScript like Python?

Spread the love

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"],

to create the statesDictionary object that has some keys and values inside.

Then we can access the object’s property values by writing


By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.