【发布时间】:2020-07-13 08:42:46
【问题描述】:
我正在尝试使用 for 循环迭代我的数组,它运行良好,现在如果我希望它在一个对象内迭代它,我该怎么做?
下面是我的代码
for (let j = 0; j < sowing.seedSownDetails.length; j++) {
this.myObj = {
sowSeedInventoryId: sowing.seedSownDetails[j]?.inventoryId,
quantity: sowing.seedSownDetails[j]?.quantity
};
console.log(this.myObj); //all the iterations work here
}
this.addComments = {
sowingId: sowing.sowingId,
cropId: sowing.cropId,
seedDetails: [this.myObj], // i want all my iteration object inside this array
seedSowingDate: sowing.sowingDate,
comments: form.value.comments
};
预期输出:
seedDetails: [
{object1},
{object2},....
]
【问题讨论】:
标签: javascript angular ecmascript-6