I have a list of user IDs and I want to make an HTTP request for each user and then return results from the server as a single array using RxJS.
Observable
.from([1020, 3050, 4400, 1720])
.mergeMap((userId: number) => {
return httpGet('/users/' + userId);
})
.map((response: Response) => {
return response.json();
})
.subscribe((user: any) => {
console.log('User:', user);
})
;
Using the code above I now receive each user as a separate emission, however, I would like to receive a single array in the end:
.subscribe((users: any[]) => {
console.log('Users:', users);
});