I would like to create in javascript an object that contains an array of other objects. i.e.
var xobj = {
d: 0,
e: 0,
f: 0
};
var topObj = {
x: [],
a: 0,
b: 0,
c: 0
};
topObj.x[0].d = 1;
topObj.x[0].e = 2;
var xx = topObj.x[0].d + topObj.x[0].e;
console.log( xx );
I would like topObj.x
to be an array of xobj
.
I am getting:
Uncaught TypeError: Cannot set property 'd' of undefined