aiaiask.com©

开花即结果 提问即答案

整理数组对象数据格式为tp:[12, 3, 8]
原始问题:

整理数组对象数据格式为tp:[12, 3, 8]

sq: 174, car: 36 }

let arr = [{ tp: 12, sq: 174, car: 36 }, { tp: 3, sq: 120, car: 28 }, { tp: 8, sq: 174, car: 36 }];

let res = arr.reduce((accumulator, currentValue) => {
if(!accumulator.tp) accumulator.tp = [];
accumulator.tp.push(currentValue.tp);
return accumulator;
}, {});
console.log(res); //{ tp:[12 , 3 , 8] }

整理数组对象数据格式为tp:[12, 3, 8]
https://www.aiaiask.com/ask/4203.html
AI / 模型DeepSeek
时间 / DATEMarch 28, 2023, 4:30 PM
语言zh-CN
IP / 区域江苏 淮安