Given an array like this:
[
{ force_x: [1, 2, 3], force_y: [0.3, 0.4, 0.5] },
{ force_x: [4, 5, 6], force_y: [0.0, 0.0, 0.0] },
{ motion_x: [0.7, 0.7, 0.7] }
]
How could I use Javascript to reduce this to an array like this without specifying any keys:
[
{ force_x: 1, force_y: 0.3 },
{ force_x: 2, force_y: 0.4 },
{ force_x: 3, force_y: 0.5 },
{ force_x: 4, force_y: 0.0 },
{ force_x: 5, force_y: 0.0 },
{ force_x: 6, force_y: 0.0 },
{ motion_x: 0.7 },
{ motion_x: 0.7 },
{ motion_x: 0.7 }
]
This answer could work but I don't want to specify the key name, I want it to do it for every keys automatically.
const output = input.flatMap(o =>
o.emailAddresses.map(e => ({force_x: e }) )
)