data structures - Javascript List-like Datastructure -


what data structure in javascript? seems list, why have curly brace , not standard "[]"?

    var states = {       "california": {        "monterey": ["salinas", "gonzales"],        "alameda": ["oakland", "berkeley"]        },     "oregon": {       "douglas": ["roseburg", "winston"],       "jackson": ["medford", "jacksonville"]       }     } 

i interested in creating sort of array has structure this:

colors: red, green, blue, orange, yellow

food: bananas, oranges

people: me, you, us, them

...

does exist in javascript?

thanks!

one of main tools available in javascript objects. they're hash maps, or dictionaries, or key-value pairs, or whatever you'd call them. key string (or symbol) , value can anything, including other objects.

to create kind of relationship you're talking about, write this:

var obj = {   colors: ['red', 'green', 'blue'],   food: ['bananas', 'oranges'],   people: ['me', 'you', 'us'] }; console.log(obj.colors); console.log(obj.food); console.log(obj.people); 

Comments