Мне нужно объединить два отдельных массива JSON в один ...
Я попытался сделать object.assign, но это просто переопределяет, и мне нужно, чтобы оно совпадало только с объектом dayOfWeek.Любое направление о том, как это может быть достигнуто без JQuery было бы предпочтительным.
Результаты не обязательно должны иметь одинаковые параметры, но если это возможно, это будет плюсом / бонусом.
var daysOfWeek = [
{
"dayOfWeek": 0,
"name": "Sunday"
},
{
"dayOfWeek": 1,
"name": "Monday"
},
{
"dayOfWeek": 2,
"name": "Tuesday"
},
{
"dayOfWeek": 3,
"name": "Wednesday"
},
{
"dayOfWeek": 4,
"name": "Thursday"
},
{
"dayOfWeek": 5,
"name": "Friday"
},
{
"dayOfWeek": 6,
"name": "Saturday"
}
]
var openingHours = [
{
"branchId": "a16ab1f8-0cfd-42eb-bc3e-25a8697003e4",
"dayOfWeek": 6,
"hours": {
"startTime": "08:00",
"endTime": "20:00"
},
"updatedAt": "Tue Jan 29 2019 10:41:33 GMT+0800 (Singapore Standard Time)",
"createdAt": "Sun Aug 19 2018 04:32:45 GMT+0800 (Singapore Standard Time)"
},
{
"branchId": "62111250-b1db-42a2-9686-daecc0442628",
"dayOfWeek": 1,
"hours": {
"startTime": "08:00",
"endTime": "20:00"
},
"updatedAt": "Sat Nov 24 2018 09:46:42 GMT+0800 (Singapore Standard Time)",
"createdAt": "Mon Jul 16 2018 17:39:56 GMT+0800 (Singapore Standard Time)"
},
{
"branchId": "f71dd838-1a09-4d78-bbf5-a3845c59e8cf",
"dayOfWeek": 3,
"hours": {
"startTime": "08:00",
"endTime": "20:00"
},
"updatedAt": "Wed Oct 31 2018 13:29:56 GMT+0800 (Singapore Standard Time)",
"createdAt": "Wed Jun 06 2018 14:09:14 GMT+0800 (Singapore Standard Time)"
}
]
необходимо объединить в
var daysOfWeek = [
{
"dayOfWeek": 0,
"name": "Sunday"
},
{
"branchId": "a16ab1f8-0cfd-42eb-bc3e-25a8697003e4",
"dayOfWeek": 1,
"name": "Monday",
"hours": {
"startTime": "08:00",
"endTime": "20:00"
},
"updatedAt": "Tue Jan 29 2019 10:41:33 GMT+0800 (Singapore Standard Time)",
"createdAt": "Sun Aug 19 2018 04:32:45 GMT+0800 (Singapore Standard Time)"
},
{
"dayOfWeek": 2,
"name": "Tuesday"
},
{
"branchId": "a16ab1f8-0cfd-42eb-bc3e-25a8697003e4",
"dayOfWeek": 3,
"name": "Wednesday",
"hours": {
"startTime": "08:00",
"endTime": "20:00"
},
"updatedAt": "Tue Jan 29 2019 10:41:33 GMT+0800 (Singapore Standard Time)",
"createdAt": "Sun Aug 19 2018 04:32:45 GMT+0800 (Singapore Standard Time)"
},
{
"dayOfWeek": 4,
"name": "Thursday"
},
{
"dayOfWeek": 5,
"name": "Friday"
},
{
"branchId": "a16ab1f8-0cfd-42eb-bc3e-25a8697003e4",
"dayOfWeek": 6,
"name": "Saturday",
"hours": {
"startTime": "08:00",
"endTime": "20:00"
},
"updatedAt": "Tue Jan 29 2019 10:41:33 GMT+0800 (Singapore Standard Time)",
"createdAt": "Sun Aug 19 2018 04:32:45 GMT+0800 (Singapore Standard Time)"
}
]