In my quest to create serialized objects within the main object, I have come up with the concept of a solar system as an example of nesting. This allows me to access a variable by referencing it like this:
universe.system1.planet4.x
The hierarchy is universe > system > planet, and so on.
I am facing a dilemma with generating nested structures. Currently, I can only successfully implement one level of nesting.
setInterval(onTimerTick, 1000);
function onTimerTick() {
var entityCount = 4;
for (i = 1; i < entityCount; i++){
console.log('system' + i)
universe['planet' + i] = [entityCount, entityCount, entityCount, entityCount];
}//entitycounts in object are placeholder for more data
console.log(universe);
}
var universe = {
}
Output
Object {
system0: [5, 5, 5, 5],
system1: [5, 5, 5, 5],
system2: [5, 5, 5, 5],
system3: [5, 5, 5, 5]
}
Every attempt at adding further nesting layers results in failure.