Currently, I am working with two sets of arrays:
$scope.selectedEmployees = ["1001", "1002"];
$scope.selectedTasks = ["Task1", "Task2"];
My goal is to create an array of objects that combine employees and tasks in a many-to-many relationship. The length of $scope.selectedEmployees and $scope.selectedTasks may vary:
newArray=[
{
"empId": 1001,
"task": "Task1"
},
{
"empId": 1001,
"task": "Task2"
},
{
"empId": 1002,
"task": "Task2"
},
{
"empId": 1002,
"task": "Task2"
}
]
I attempted the following method:
var newArray=[];
for (var i = 0; i <$scope.selectedEmployees.length; i++) {
for (var j = 0; j <$scope.selectedTasks .length; j++) {
newArray.push({"empId":$scope.selectedEmployees[i],
"task":$scope.selectedIntervention[j]
})
}
}
However, I am struggling to achieve the desired format. Any assistance would be greatly appreciated.