[ { "id": "07c1e8cbd5b383b347e38336164b24bd", "traceId": null, "deleteFlag": null, "createTime": "2023-07-11 17:28:25", "updateTime": null, "createUser": null, "updateUser": null, "signId": "483e212f3a896666fd5f8606a346b0bc", "vehicleId": "a80927637930906222f4cc37cbf33bbd", "vehicleCode": "京ADR738", "billType": 2, "billCode": "DZ20230711001", "billPrice": 0.12, "mileageLast": 100, "mileageCurrent": 600, "totalAmount": 60, "paidAmount": 0, "payableAmount": 60, "billStartTime": "2023-06-25 12:00:00", "billEndTime": "2023-07-25 11:59:59", "generate": 1 }, { "id": "868bd794088fe38b186816110081a70e", "traceId": null, "deleteFlag": null, "createTime": "2023-07-11 17:28:25", "updateTime": null, "createUser": null, "updateUser": null, "signId": "483e212f3a896666fd5f8606a346b0bc", "vehicleId": "ae7c08facdcabd0febb231038d2fee22", "vehicleCode": "京ADR653", "billType": 2, "billCode": "DZ20230711001", "billPrice": 0.12, "mileageLast": 222, "mileageCurrent": 500, "totalAmount": 33.36, "paidAmount": 0, "payableAmount": 33.36, "billStartTime": "2023-06-25 12:00:00", "billEndTime": "2023-07-25 11:59:59", "generate": 1 } ]给上述数据格式添加 一个meilageing属性,值为mileageCurrent减去mileageLast的值 前端 es6
时间: 2023-07-17 19:02:19 浏览: 133
R语言数据分析入门基础:07、 数据展现:R07c.flv
在前端使用ES6语法,可以通过遍历给每个对象添加一个新的属性`mileageDiff`,其值为`mileageCurrent - mileageLast`。下面是一个示例代码:
```javascript
const data = [
{
"id": "07c1e8cbd5b383b347e38336164b24bd",
"traceId": null,
"deleteFlag": null,
"createTime": "2023-07-11 17:28:25",
"updateTime": null,
"createUser": null,
"updateUser": null,
"signId": "483e212f3a896666fd5f8606a346b0bc",
"vehicleId": "a80927637930906222f4cc37cbf33bbd",
"vehicleCode": "京ADR738",
"billType": 2,
"billCode": "DZ20230711001",
"billPrice": 0.12,
"mileageLast": 100,
"mileageCurrent": 600,
"totalAmount": 60,
"paidAmount": 0,
"payableAmount": 60,
"billStartTime": "2023-06-25 12:00:00",
"billEndTime": "2023-07-25 11:59:59",
"generate": 1
},
{
"id": "868bd794088fe38b186816110081a70e",
"traceId": null,
"deleteFlag": null,
"createTime": "2023-07-11 17:28:25",
"updateTime": null,
"createUser": null,
"updateUser": null,
"signId": "483e212f3a896666fd5f8606a346b0bc",
"vehicleId": "ae7c08facdcabd0febb231038d2fee22",
"vehicleCode": "京ADR653",
"billType": 2,
"billCode": "DZ20230711001",
"billPrice": 0.12,
"mileageLast": 222,
"mileageCurrent": 500,
"totalAmount": 33.36,
"paidAmount": 0,
"payableAmount": 33.36,
"billStartTime": "2023-06-25 12:00:00",
"billEndTime": "2023-07-25 11:59:59",
"generate": 1
}
];
const newData = data.map(item => {
return {
...item,
mileageDiff: item.mileageCurrent - item.mileageLast
};
});
console.log(newData);
```
这样,`newData`数组中的每个对象都会新增一个`mileageDiff`属性,其值为对应对象的`mileageCurrent - mileageLast`的差值。你可以在控制台中查看`newData`数组的输出结果。
阅读全文