noc_coder noc_coder - 7 months ago 65
Javascript Question

Javascript List-like Datastructure

What data structure is this in JavaScript? Is seems like a list, but then why does it have a curly brace and not the standard "[]"?

var states = {
"California": {
"Monterey": ["Salinas", "Gonzales"],
"Alameda": ["Oakland", "Berkeley"]
"Oregon": {
"Douglas": ["Roseburg", "Winston"],
"Jackson": ["Medford", "Jacksonville"]

I am interested in creating some sort of array that has a structure like this:

Colors: Red, Green, Blue, Orange, Yellow

Food: Bananas, Oranges

People: Me, You, Us, Them


Does something like this exist in Javascript?


var arrayObj = [];

var obj = {};
var innerArray = ['Red', 'Green', 'Blue', 'Orange', 'Yellow'];
var secondArray = ['Me', 'You', 'Us', 'Them'];
obj['Colors'] = innerArray;
obj['People'] = secondArray ;
arrayObj .push(obj);

You can do like this