【发布时间】:2020-10-23 08:55:28
【问题描述】:
我正在尝试展平一个看起来像这样的对象,
{
O75376: {
ABC: [],
XYZ: ["a", "b", "c"],
FGH: ["x", "y", "z"]
},
O75378: {
ABC: [],
XYZ: ["a", "b", "c"],
FGH: ["x", "y", "z"]
},
}
我希望它像075376: ["a","b","c","x","y","z"], 075378: ["a","b","c","x","y","z"],
const flat = reduce(data, (accumulator, content, key) => {
accumulator[key] = flatMap(content, (x, y) => {
return map(x, b => {
return y + '~' + b
})
})
return accumulator;
}, {});
这适用于 lodash,但我无法弄清楚这在 ES6 中是如何实现的。
【问题讨论】:
标签: javascript arrays ecmascript-6 lodash reduce