views:

71

answers:

3

i need to make a dictionary in javascript like this

i dont remember the exact notation, but it was something like:

states_dictionary={ CT=[alex,harry], AK=[liza,alex], TX=[fred, harry] ........ }

is there such a thing in javascript?

+2  A: 

Use JavaScript objects. You can access their properties like keys in a dictionary. This is the foundation of JSON. The syntax is similar to Python dictionaries. See: JSON.org

Adam
+1  A: 

I think the HashSet class does what you want.

JonC
This is Javascript, not Java. `HashSet` is not like a `dict` anyways.
NullUserException
+1  A: 

There are no real associative arrays in Javascript. You can try using objects:

var x = new Object();
x["Key"] = "Value";

However with objects it is not possible to use typical array properties or methods like array.length. At least it is possible to access the "object-array" in a for-in-loop.

Vash