title: How to loop through JSON object retrieved via Http Angular 2/ Typescript
body: <p>I'm trying to fetch some specific data from my JSON file via http. JSON looks like this:</p>
  
  <pre><code>[{"name":"Name1","perc":33},{"name":"Name2","perc":22},{"name":"Name3","perc":41}]
  </code></pre>
  
  <p>I'm trying to loop through this retrieved object, I'm retrieving it like so:</p>
  
  <pre><code>  this._postService.getParams(_url).subscribe(
    data =&gt; {
      this.results = data.Results
    },
    error =&gt; console.log(error),
    () =&gt; console.log('Done')
    );
  </code></pre>
  
  <p>getParams() fetches the data like this</p>
  
  <pre><code>    getParams(url: string) {
      return this._http.get(url)
          .map(res =&gt; res.json());
  }
  </code></pre>
  
  <p>I made an interface for data retrieved, placed it in the same .component.ts file where the service is being called</p>
  
  <pre><code>/*Interface for Stats */
  interface stats {
  name: string;
  percent: number;
  }
  </code></pre>
  
  <p>I plan to loop through the object I retrieved and store them in a local array and then loop through that and display them. How can I iterate through the JSON object in my component file? I tried many different for loops and they all failed.</p>
  
  <p>I attempted this one and it failed, json was not being recognized by typescript</p>
  
  <pre><code>let list: string[] = [];
  json.Results.forEach(element =&gt; {
  list.push(element.Id);
  });
  </code></pre>
  
  <p>I'm perfectly able to retrieve the data, because I console logged the 3 objects I received. </p>