I have a dataset that looks like below, (second code). I want to merge all my data to one big object, see example below. I tried to do it with a forEach, but I'm not getting the right results back.
What I want to achieve:
var arr2 = [{
"date": "20170314",
"steps": 620,
"nutrition.calories": 1634,
"nutrition.fat.total": 57.22602462768555,
"nutrition.protein": 188.070068359375,
"nutrition.carbs.total": 83.85400390625
}, {
"date": "20170314",
"steps": 620,
"nutrition.calories": 1634,
"nutrition.fat.total": 57.22602462768555,
"nutrition.protein": 188.070068359375,
"nutrition.carbs.total": 83.85400390625
}]
This is how my current array looks like:
var array = [
{
"type": "steps",
"data": [
{
"startDate": "2017-03-12T23:00:00.000Z",
"endDate": "2017-03-13T23:00:00.000Z",
"value": 1031,
"unit": "count"
}, {
"startDate": "2017-03-13T23:00:00.000Z",
"endDate": "2017-03-14T23:00:00.000Z",
"value": 620,
"unit": "count"
}
]
}, {
"type": "nutrition.calories",
"data": [
{
"startDate": "2017-03-12T23:00:00.000Z",
"endDate": "2017-03-13T23:00:00.000Z",
"value": 0,
"unit": "kcal"
}, {
"startDate": "2017-03-13T23:00:00.000Z",
"endDate": "2017-03-14T23:00:00.000Z",
"value": 1634.100463867188,
"unit": "kcal"
}
]
}, {
"type": "nutrition.fat.total",
"data": [
{
"startDate": "2017-03-12T23:00:00.000Z",
"endDate": "2017-03-13T23:00:00.000Z",
"value": 0,
"unit": "g"
}, {
"startDate": "2017-03-13T23:00:00.000Z",
"endDate": "2017-03-14T23:00:00.000Z",
"value": 57.22602462768555,
"unit": "g"
}
]
}, {
"type": "nutrition.protein",
"data": [
{
"startDate": "2017-03-12T23:00:00.000Z",
"endDate": "2017-03-13T23:00:00.000Z",
"value": 0,
"unit": "g"
}, {
"startDate": "2017-03-13T23:00:00.000Z",
"endDate": "2017-03-14T23:00:00.000Z",
"value": 188.070068359375,
"unit": "g"
}
]
}, {
"type": "nutrition.carbs.total",
"data": [
{
"startDate": "2017-03-12T23:00:00.000Z",
"endDate": "2017-03-13T23:00:00.000Z",
"value": 0,
"unit": "g"
}, {
"startDate": "2017-03-13T23:00:00.000Z",
"endDate": "2017-03-14T23:00:00.000Z",
"value": 83.85400390625,
"unit": "g"
}
]
}
]
Can someone please help me with it. Foreach loop is not working.
Kab
