title: TypeScript (Angular) - read text file line by line
body: <p>I have a problem with reading a text files LINE BY LINE. Using console.log(file) works perfectly fine, but I need each particular line to do something with them, so  here's what I've done so far.</p>
  
  <p>In api.service.ts I have a function that downloads the file from the server, and the function itself looks like this:</p>
  
  <pre><code>getFile(url: string): Observable&lt;File&gt; {
    return this.httpClient.get&lt;File&gt;(url, {responseType: "text"});
  }
  </code></pre>
  
  <p>Then in app.component.ts I define the private 'resultFile: File' field and assign the incoming file to this variable</p>
  
  <pre><code>getFile() {
      this.apiService.getFile('http://127.0.0.1:8000/media/results/MINERvA/CC0pi/v1.0/nuwro.txt').subscribe(file =&gt; {
        this.resultFile = file;
        console.log(this.resultFile);
      });
    }
  </code></pre>
  
  <p>As I mentioned before printing the content of resultFile using console.log() works just fine. File is properly formatted (with new lines), but when I loop through the resultFile</p>
  
  <pre><code>for (const line of resultFile){
    console.log(line);
  }
  </code></pre>
  
  <p>It prints each single character instead of each single line. I think the problem may be the responseType: "text" which converts the content to plain string, but I couldn't find any solution for this. Sorry for such dumb question, but I've never used JS/TS before.</p>