私は以下のようなデータセットを持っています(2番目のコード)。すべてのデータを1つの大きなオブジェクトにマージしたいのですが、下の例を参照してください。私はforEachでそれをやろうとしましたが、正しい結果が得られません。私が達成したい何入れ子配列のデータを1つの配列にマージする
:
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
}]
これは私の現在の配列がどのように見えるかです:誰かがそれで私を助けてくださいすることができ
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"
}
]
}
]
。 Foreachループが機能していません。
甲
おかげ@Ilija、私は正しいを適用することができませんでしたモバイルウェブサイトからフォーマットします。 –
私はこの解決策が働いていることを確認できます。ありがとう!!! – kabus
@kabus:解決策があなたのために働くなら、受け入れてUpvote。コメントありがとうございます。 –