Array variable outside subscription is empty

My goal is to read a csv file into an array in an Angular app in TypeScript.

I created a function which subscribes to another function which returns an observable and puts its value in a variable.

  processesData: any[] = new Array();

  loadCvs(files: FileList) {
    const file: File = files[0];
    if(files && files.length > 0) {
      this.getCsv(file).subscribe((output: any[]) => {
        this.processesData = output.slice();

  getCsv(file: File): Observable<any[]> {
    const sub = new Subject<any[]>();
    //File reader method
    let reader: FileReader = new FileReader();

    let tmp: any[] = new Array();
    reader.onload = () => {
      let csv: any = reader.result;
      let allTextLines = [];
      allTextLines = csv.split(/\r|\n|\r/);

      const header = allTextLines[0];
      const numberOfCols = header.split(',').length;

      for(let i = 0; i < allTextLines.length; i++) {
        let line = allTextLines[i];
        let lineData = line.split(',');

        if (lineData.length > numberOfCols) {
          let temp = lineData.slice(1,3).join(',');
          lineData[1] = temp;
          lineData.splice(2, 1);

    return sub.asObservable();

When I log this.processData inside the subscription everything seems to work fine. However, when I log it outside the variable is empty.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum