title: Combining observables of array objects
body: <p>How do you combine two or more observable of array i.e. <code>Observable&lt;Object[]&gt;, Observable&lt;Object[]&gt;</code> using rxjs in order to return one <code>Observable&lt;Object[]&gt;</code>?</p>
  
  <p><code>forkJoin</code> and <code>merge</code> are emitting the two <code>Observable&lt;Object[]&gt;</code> arrays independently.</p>
  
  <pre><code>getEmployeesLeavesByEmployeeNumber2(employeeNumber,afromDate,atoDate) {
      const scenario1 = this.afs.collection(`${environment.FB_LEAVES}`, ref =&gt; {
          let query: firebase.firestore.CollectionReference | firebase.firestore.Query = ref;
          query = query.where("employeeNumber", "==", employeeNumber);
          query = query.where("fromDate","&gt;=",afromDate);
          query = query.where("fromDate","&lt;=",atoDate);
          return query;
  
      }).snapshotChanges()
          .pipe(take(1))
          .pipe(
              map(changes =&gt; {
                  return changes.map(a =&gt; {
                      const data = a.payload.doc.data() as Leave;
                      data.docId = a.payload.doc.id;
                      return data;
                  })
              })
          ).pipe(map(leaves =&gt; {
              let leavesArr=leaves.filter(leave =&gt; leave.status!==environment.LEAVE_STATUS_DECLINED)
              return leavesArr;
          }));
  
      const scenario2 = this.afs.collection(`${environment.FB_LEAVES}`, ref =&gt; {
          let query: firebase.firestore.CollectionReference | firebase.firestore.Query = ref;
          query = query.where("employeeNumber", "==", employeeNumber);
          query = query.where("toDate","&lt;=",afromDate);
          query = query.where("toDate","&lt;=",atoDate);
          return query;
  
      }).snapshotChanges()
          .pipe(take(1))
          .pipe(
              map(changes =&gt; {
                  return changes.map(a =&gt; {
                      const data = a.payload.doc.data() as Leave;
                      data.docId = a.payload.doc.id;
                      return data;
                  })
              })
          ).pipe(map(leaves =&gt; {
              let leavesArr=leaves.filter(leave =&gt; leave.status!==environment.LEAVE_STATUS_DECLINED)
              return leavesArr;
          }));
  
      const scenario3 = this.afs.collection(`${environment.FB_LEAVES}`, ref =&gt; {
          let query: firebase.firestore.CollectionReference | firebase.firestore.Query = ref;
          query = query.where("employeeNumber", "==", employeeNumber);
          query = query.where("fromDate","&lt;=",afromDate);
          return query;
  
      }).snapshotChanges()
          .pipe(take(1))
          .pipe(
              map(changes =&gt; {
                  return changes.map(a =&gt; {
                      const data = a.payload.doc.data() as Leave;
                      data.docId = a.payload.doc.id;
                      return data;
                  })
              })
          ).pipe(
              filter(leave =&gt; {
                  return leave!==undefined;
              })
          );
      return merge(scenario1,scenario2);
  }
  </code></pre>
  
  <p>I am expecting a single observable of array but getting 2 i.e.</p>
  
  <pre><code>emp's leaves:  [{…}]
  assign.component.ts:198 leaves array length at assignment error  1
  assign.component.ts:168 emp's leaves:  (2) [{…}, {…}]
  assign.component.ts:198 leaves array length at assignment error  2
  </code></pre>