I'm struggling with array manipulation when they are arrays of different types. My problem is rather simple, but I would still appreciate any assistance.
I have the following two classes:
export interface Group {
gId: number;
gName: string;
}
export interface UserGroup {
uId: number;
gId: number;
}
I have two arrays:
finalUserGroupsToUpdate: UserGroup[];
pickListUserAssociatedGroups: Group[];
The array of Group is populated and looks like this in the console:
(3) [{…}, {…}, {…}]
0: {gId: 1, gName: "Manager"}
1: {gId: 2, gName: "Nurse"}
2: {gId: 3, gName: "Audit"}
I also have a uId that is accessible through the active route in Angular (for this example it can just be a local variable):
currentUserID = 1;
What I want to be able to do is push each gId of the array of Group into the array of UserGroup while appending currentUserId as the uId.
The final result should look something like:
(3) [{…}, {…}, {…}]
0: {gId: 1, uId: 1}
1: {gId: 2, uId: 1}
2: {gId: 3, uId: 1}