title: Loop an observable in Angular2
body: <p>How can I simply loop an observable?</p>
  
  <p>Let's say I want to execute an observable five times it would go something like the code below.</p>
  
  <p>What happens in my code is that </p>
  
  <p>(1) I query and a function returns a json called 'posts'</p>
  
  <p>(2) for every 'posts' I want to execute an observable</p>
  
  <p>(3) I push the result of step (2) to my array</p>
  
  <pre><code>// (1)
  this.communityPostProvider.query({})
    .subscribe(posts =&gt; {
  
      // (2)
      for(let i=0; i &lt; posts.length; i++) {
          this.getFeaturedApi(i)
          .subscribe(result =&gt; {
              // (3)
              this.communityPosts.push(posts[i]);
              this.communityPosts[i].featured_media = result;      
        });
     });
  </code></pre>
  
  <p>The problem with this is that the for loop completely executes before my observable can. By the time the observable executes, the for loop is already finished.</p>
  
  <p>I am new to angular2. Please help!</p>