我有一个JavaScript数组,copyCommands
,我想将一些项目推入。但是,我似乎无法正确地将另一个项目数组添加到父对象autoGenData
。
//autoGenData is the object, copyCommands is an array
autoGenData.copyCommands.push({
CopyFrom: UnitFrom,
//CopyTo: //array that needs to hold CopyOptions and Unit
});
//Need to add these into CopyTo
//CopyOptions: checkedItems,
//Unit: localUnitTo
将CopyOptions
和unit
添加到CopyTo
命令的push
部分的正确语法是什么?
答案 0 :(得分:1)
我认为你正在寻找这样的东西:
autoGenData.copyCommands.push({
CopyFrom: UnitFrom,
CopyTo: {
CopyOptions: checkedItems,
Unit: localUnitTo
}
});
答案 1 :(得分:0)
您可以尝试以下操作:
var x = [1, 2, 3, 4];
var y = [5, 6, 7];
x.push(...y);