更新时间:2022-12-11 08:14:49
在您的代码中,如果您已经有r[id]
,则没有分配其余值.因此,请像这样更改它:
In your code, if you already have a r[id]
, you didn't assign the rest values. So change it like this:
const result = Object.values(
array.reduce((r, { data }) => {
Object.entries(data).forEach(([id, { ...el }]) => {
r[id] = {
...r[id], // this is the point
id,
...el
};
});
return r;
}, {})
);