In my coding environment, I am working with two arrays. The first array is called `$scope.workingSchedules` and it contains data related to working hours for different days of the week.
$scope.workingSchedules=[
{
workingDay:"MONDAY",
workingHours:[{fromTime:'1222',toTime:'1300'}]
},
workingDay:"MONDAY",
workingHours:[{fromTime:'1222',toTime:'1300'}]
];
This array can store information for multiple days of the week. Additionally, I have another array named `$scope.workingTime` which has all days of the week listed with empty `workingHours` fields.
$scope.workingTime = [
{ workingDay: 'MONDAY',
workingHours: []
},
{ workingDay: 'TUESDAY',
workingHours: []
},
{ workingDay: 'WEDNESDAY',
workingHours: []
},
{ workingDay: 'THURSDAY',
workingHours: []
},
{ workingDay: 'FRIDAY',
workingHours: []
},
{ workingDay: 'SATURDAY',
workingHours: []
},
{ workingDay: 'SUNDAY',
workingHours: []
}
];
My goal is to merge the data from the first array (`workingSchedules[]`) into the second array (`workingTime[]`) while keeping any days that are in the second array but not in the first array intact.
To achieve this, I have written the following code:
for(var i=0;i<$scope.workingTime[i].length;i++)
{
for (var j=0;j<$scope.workingSchedules[j].length;j++)
{
if($scope.workingTime[i].workingDay==$scope.workingSchedules[j].workingDay)
{
$scope.workingTime[i]=$scope.workingSchedules[j];
}
}
}
Any assistance or suggestions on how to improve this code would be greatly appreciated. Thank you!