I have an array of objects that contain other objects. At the moment the way I declare them is pretty long winded. Is there are more condense way to do the following:
function city(name,population)
{
this.name = name;
this.population = population;
}
function state(name)
{
this.name= name;
this.cities = new Array();
}
function country(name)
{
this.name= name;
this.states = new Array();
}
Countries = new Array();
Countries[0] = new Country("USA");
Countries[0].states[0] = new State("NH");
Countries[0].states[0].cities[0] = new city("Concord",12345);
Countries[0].states[0].cities[1] = new city("Foo", 456);
...
Countries[3].states[6].cities[35] = new city("blah", 345);
Is there a way to declare this setup that isn't so verbose, something similair to how an xml would be layed out, something like:
data =
usa
NH
concord: 34253
foo: 3423
blah: 99523
NC
place: 23522
Uk
foo
bar: 35929
yah: 3452
I can't figure out how to nest array declarations without having to constantly repeat the variable names.