title: Angular subscribe push object to array
body: <p>I am making angular application and where i am having an empty array like,</p>
  
  <pre><code>  users: any = [];
  </code></pre>
  
  <p>Then i am making a service call in <code>ngOnInit</code> to store the data into <code>users</code> array like,</p>
  
  <pre><code>  ngOnInit() {
  
      //Getting the data from json
      this.httpClient.get('https://api.myjson.com/bins/n5p2m').subscribe((response: any) =&gt; {
        console.log("response", response.data);
        response.data.forEach(element =&gt; {
          //Pusing the data to users array
          this.users.push(element);
        });
      })
  
      //Trying to get the complete array after push of the element from the service response data
      console.log("users array", this.users);
      //But it shows empty array
    }
  </code></pre>
  
  <p>But i am unable to get the data in <code>console.log("users array", this.users);</code> as because the service call makes a delay..</p>
  
  <p>How to push the data into <code>this.users</code> and when we call outside of the service it should have the filled data and not empty as like now..</p>
  
  <p>Also made a <strong>working stackblitz</strong> regarding it <a href="https://stackblitz.com/edit/angular-q3yphw" rel="nofollow noreferrer">https://stackblitz.com/edit/angular-q3yphw</a></p>
  
  <p>Please see the console which has current result..</p>
  
  <p><strong>Current result</strong> in <code>console.log("users array", this.users);</code> is empty array <strong>[]</strong>.</p>
  
  <p>So i am <strong>expecting</strong> the following <strong>result</strong> in <code>console.log("users array", this.users);</code> outside the service and inside <code>ngOnInit</code>,</p>
  
  <pre><code>[
  {"id":1,"value":"User One"},
  {"id":2,"value":"User Two"},
  {"id":3,"value":"User Three"}
  ]
  </code></pre>
  
  <p>As i am new in angular kindly help me to achieve the expected result..</p>