抱歉,如果标题有点误导,我是js新手,所以idk如何解释我想正确地做什么,所以我将展示我的代码和我的期望.
所以我有一组对象
const mi_array = [{
text: "1st title",
col2015: 81.8,
col2016: 86.4,
col2017: 67.3,
col2018: 70.8,
col2019: 67.6
},{
text: "2nd title",
col2015: 90.8,
col2016: 67.4,
col2017: 39.3,
col2018: 50.8,
col2019: 95.6
}];
我需要这样的东西
const new_array = [{
name: "1st title",
data: [81.8,86.4,67.3,70.8,67.6]
},{
name: "2nd title",
data: [90.8,67.4,39.3,50.8,95.6]
}];
我一直在寻找如何做到这一点,但这是我迄今为止发现的全部,它接近我需要的,但还不完全存在
const new_array = [];
mi_array.forEach(value => {
for (let key in value) {
new_array.push(value[key]);
}
});
console.log(new_array);
但我的输出是这样的
["1st title", 81.8, 86.4, 67.3, 70.8, 67.6, "2nd title", 90.8, 67.4, 39.3, 50.8, 95.6];