title: Transferring data from subscribe() to variable in Angular 6
body: <p>In the below function, console.log(data) is returning my payload, but I am getting "undefined" in console.log(this.finalData). What is the best practice for storing the subscribed data to my this.finalData variable?</p>
  
  <p>component.ts</p>
  
  <pre><code>getFavorites(){
    this.jobService.getFavoritesFromDB().subscribe((data) =&gt;  { 
     console.log(data)
     this.finalData = data
    });
    console.log(this.finalData)
  
   }
  </code></pre>
  
  <p>service.ts</p>
  
  <pre><code>getFavoritesFromDB(){
      return this.http.get("http://localhost:3000/post");
  }
  </code></pre>