I have object of array of object. How to convert array of objects to array of arrays?
input = [
{
time: "2020-7",
tasks: [
{code: "p1", value: 1234},
{ code: "p2", value: 3445 },
]
},
{
time: "2020-8",
tasks: [
{ code: "p1", value: 3333 },
{ code: "p2", value: 4444 },
]
}
]
I tried use forEach
let dataConvert=[], date=[],data=[];
input.forEach(x=>{
return date = [...date, x.time]
})
console.log(date)
input.forEach(x=>{
x.tasks.forEach(y=>{
data = [...data,y.value]
})
})
console.log(data);
dataConvert= [...dataConvert,date,data]
And get the results
dataConvert = [
["2020-7", "2020-8"],
[1234, 3445, 3333, 4444]
]
I want the output looks like this:
output = [
["2020-7", "2020-8"],
["p1", 1234, 3333],
["p2", 3445, 4444],
]
Please help me.