title: Using MergeMap with the array of data received from another observable - RxJs Angular
body: <p>I have a fetchDrives method which will return an observable which on subscription will return a list of drives</p>
  
  <pre><code>this.fetchDrives(points).subscribe(drives =&gt; {
       console.log(drives);
  });
  </code></pre>
  
  <p>Assume The drives array which I got on subscription look some what like this</p>
  
  <pre><code>[ {driveId: 1}, {driveId: 2}, {driveId: 3} ]
  </code></pre>
  
  <p>Now I need to use the driveId one by one and make three calls ( three because length of the drives array is 3 ) by passing driveId to each api call.I need to pass driveId to the below method one at a time and get the lat and lon and store the result of three calls in an array.</p>
  
  <pre><code>this.getLatLong(driveId).subscribe( res =&gt; console.log(res))
  </code></pre>
  
  <p>The res will contain an object like <code>{ lat: 12, lon: 54 }</code></p>
  
  <p>I don't want to do two subscriptions, is there a way I can use the Rxjs operators and achieve this with one subscription using the result of previous observable, loop through the drives array and make three calls to <code>getLatLong</code> method using <code>mergeMap</code> as the sequence of the calls doesn't matter and store the result of those three calls in an array?</p>
  
  <p>I tried using scan operator to loop through but failed to use it to get the desired output</p>
  
  <p>Thanks for the help in advance :)</p>