var Schedulearray1 =
[{
"scheduleid": "id123",
"timestart": "08:00",
"timeend": "20:00",
},
{
"scheduleid": "id456",
"timestart": "08:00",
"timeend": "20:00",
}]
var Schedulearray2 =
[{
"scheduleid": "id123",
"timestart": "08:00",
"timeend": "20:00",
},
{
"scheduleid": "id789",
"timestart": "08:00",
"timeend": "20:00",
}]
i want to merge these two json arrays i used :
Schedulearray1 = Schedulearray1.concat(Schedulearray2);
but this results in having 2 id123
for the schedule like follow
[{
"scheduleid": "id123",
"timestart": "08:00",
"timeend": "20:00",
},
{
"scheduleid": "id456",
"timestart": "08:00",
"timeend": "20:00",
},
{
"scheduleid": "id123",
"timestart": "08:00",
"timeend": "20:00",
},
{
"scheduleid": "id789",
"timestart": "08:00",
"timeend": "20:00",
}]
i want it to update the scheduleid
timestart
and timeend
in Schedulearray2 by the ones available in Schedulearray1.
I have tried this from the similar question that you suggested:
var mergedList = _.map(Schedulearray1, function(item) {
return _.extend(item, _.findWhere(Schedulearray2, { scheduleid: item.id }));
});
it resulted in an error Uncaught ReferenceError: _ is not defined