title: How to use observable subscription in forloop angular 7
body: <p>I have an array users:</p>
  
  <pre><code>[0: {id:123, firstname:'xyz', lastname:'abc'}, 1:{id:456, firstname:'foo', lastname:'bar'}, 3:{id:567, firstname:'bar', lastname:'baz'}]
  </code></pre>
  
  <p>I have to loop through this array and call service API to get user appointments.</p>
  
  <p><strong>Method 1</strong> <em>which i feel is not best practice but solves issue</em></p>
  
  <pre><code>let userAppointments = []
    for (let user of this.users) {
  
      this._service
        .getUsersAppointments(
          {
            date: this.todayDate,
            id: user.id
          },
          this.token
        )
        .subscribe(res =&gt; {
  
         // Modifying array as per requirements-----
  
          userAppointments.push({
            id: user.id,
            name: `${user.firstname} ${user.lastname}`,
            appointments: res
          });
        });
  
    }
  
    this.appointments = userAppointments 
  </code></pre>
  
  <p><strong>method 2:</strong> using <em>forkJoin</em> </p>
  
  <p>Issue: I cannot access user firstname and last name when I finally get response from all calls. I need those details in my final array this.appointments i.e after calling subscribe where I am assigning <code>res to this.appointments</code></p>
  
  <pre><code>        forkJoin(
      this.users
        .map(res =&gt;
          this._service.getUsersAppointments(
            {
            date: this.todayDate,
            id: res.id
  
            },
            this.token
          )
        )
        .map(response =&gt; response)
    ).subscribe(res =&gt; {
  
      // how can I access 'user object' keys like: firstname, id here--------------
  
      this.appointments = res;
  
    });
  </code></pre>
  
  <p>Please let me know if my problem is not clear.</p>
  
  <p>Referred <a href="https://stackoverflow.com/questions/45117273/how-to-use-multiple-http-requests-in-angular-2">SO answer</a> and <a href="https://codereview.stackexchange.com/questions/160077/making-multiple-http-request-angular2">codereview question</a> for method 2</p>