需求:将数组funListT01循环数组 funListT01:[ { id:1, name:'天线1XYZ角度变化情况', data:[ { id:1, time:'2022-10-10 00:00:00', amount:10 }, { id:2, time:'2022-10-11 00:00:00', amount:20 }, { id:2, time:'2022-10-12 00:00:00', amount:20 }, ] }, { id:2, name:'天线2XYZ角度变化情况', data:[ { id:1, time:'2022-10-10 00:00:00', amount:40 }, { id:2, time:'2022-10-11 00:00:00', amount:10 }, { id:2, time:'2022-10-12 00:00:00', amount:60 }, ] }, ], ,组成list数组 list=[ { data:[10, 20, 20, 30, 40, 50, 60, 70], name:"天线1XYZ角度变化情况", stack:"Total", type:"line" }, { data:[40, 10, 60, 90, 120, 30, 200, 20], name:"天线1XYZ角度变化情况", stack:"Total", type:"line" } ]
时间: 2024-02-20 08:57:18 浏览: 65
js合并两个数组生成合并后的key:value数组
可以使用循环遍历数组funListT01,然后在每个对象中获取data和name属性,将data属性中的amount值取出来组成一个新的数组,并将name、stack和type属性添加到一个新的对象中,最后将新的对象添加到list数组中即可。以下是示例代码:
```javascript
let list = [];
for(let item of funListT01) {
let dataArr = item.data.map(dataItem => dataItem.amount);
let newObj = {
data: dataArr,
name: item.name,
stack: "Total",
type: "line"
};
list.push(newObj);
}
```
阅读全文