我想用文字来做这件事:
newObject.object[0].time = 1200;
但是以下代码给出了错误:
var newObject = {
object[0].time: 1200
};
有没有办法用文字构建这样的对象?
答案 0 :(得分:3)
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