I have the following object:
let obj = {
"productData": [{
"id": 0,
"daily_netProfit": 1.35208688924,
"daily_grossProfit": 1.35448688924,
"daily_costs": 0.0024,
"created_at": "2018-06-18"
},
{
"id": 1,
"daily_netProfit": 1.35208688924,
"daily_grossProfit": 1.35448688924,
"daily_costs": 0.0024,
"created_at": "2018-06-19"
}
]
}
let dataSet = obj.productData.map((item, i) => [
item.daily_netProfit,
item.daily_grossProfit,
item.daily_costs,
item.created_at,
])
console.log(dataSet)
As you can see the above map function constructs an array within an array. However, my final result array with objects should look like the following:
[{
daily_netProfit: 1.35208688924,
daily_grossProfit: 1.35448688924,
daily_costs: 0.0024,
day: "2018-06-18"
},
{
daily_netProfit: 1.35208688924,
daily_grossProfit: 1.35448688924,
daily_costs: 0.0024,
day: "2018-06-19"
}
],
Is there a map function to construct the above array-object?
I appreciate your replies!