Categories
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"],
};
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]

By John Au-Yeung

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

Leave a Reply

Your email address will not be published.