How to zip any number of arrays, which are properties of an object, in a specific format in javascript to get the following outcome?
This is the original object.
const items = {
distance: [1,5,12, ...],
time: [10,20,30,..],
...
}
expected outcome :
const result = [
{distance: 1, time: 10},
{distance: 5, time: 20},
{distance: 12, time: 30},
...
]
I tried with loadash zip and vanilla js mapping and all. It is not working!
This is a sample of what I have tried:
But not working!
zip(
Object.entries(items ).map(
([key, values]) =>
values.map((val, index) => ({
[key]: val[index],
}))
)
))