noc_coder noc_coder - 1 year ago 107
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?


Answer Source
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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download