You can do it a little more cleanly with Array.map, but the speed of it will be negligable:
userModelResponse.orders = responseOrderData.map((e) => {
const orderModel = new OrderModel();
orderModel.price = e.price;
orderModel.weight = e.weight;
orderModel.time = e.time;
return orderModel;
});
If the OrderModel
constructor accepts something like an object of default values, then you could do something like:
userModelResponse.orders = responseOrderData.map(e => new OrderModel(e));
Edit: Updated the new OrderModel
part following @Bergi's comment.
The constructor of OrderModel
would need to look something like:
class OrderModel {
constructor(order) {
this.price = order.price;
this.weight = order.weight;
this.time = order.time;
}
...
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…