Reputation: 1051
I want to do this using literals:
newObject.object[0].time = 1200;
But the following code gives an error:
var newObject = {
object[0].time: 1200
};
Is there any way to construct such an objects using literals?
Upvotes: 1
Views: 31
Reputation: 145398
var newObject = { // base object
object: [ // array as "newObject.object"
{ // object as a first element of array
time: 1200
}
]
};
console.log(newObject.object[0].time); // 1200
Upvotes: 3