Yes, you can create a dictionary in JavaScript using an object, and you can store arrays as the values for each key. The syntax you’re looking for is quite close to what JavaScript uses. Here’s the correct way to write it:

let statesDictionary = {
  CT: ["alex", "harry"],
  AK: ["liza", "alex"],
  TX: ["fred", "harry"]
};

In this example:

  • CT, AK, and TX are the keys (representing states).
  • The values are arrays of names associated with each state.

You can access the data like this:

console.log(statesDictionary.CT);  // Output: ["alex", "harry"]
console.log(statesDictionary.AK);  // Output: ["liza", "alex"]

Need Help With Javascript Development?

Work with our skilled Javascript developers to accelerate your project and boost its performance.

Hire JavaScript Developers

Support On Demand!

Related Q&A