title: Unsubscribing an array of subscriptions
body: <p>In an Angular app, I'm managing my subscriptions by pushing them all into an array, then looping through it and unsubscribing during <code>ngOnDestroy</code>.</p>
  
  <pre><code>private subscriptions: Subscription[] = []
  this.subscriptions.push(someObservable.subscribe(foo =&gt; bar))
  </code></pre>
  
  <p>My problem is that I haven't found a sufficiently clean way to handle the unsubscription.  The ideal way would be a simple </p>
  
  <pre><code>ngOnDestroy () {
      this.subscriptions.forEach(subscription =&gt; subscription.unsubscribe())
  }
  </code></pre>
  
  <p>but this doesn't work.  Notably, I'm still receiving Firebase permission errors after logging out (which doesn't happen with the "working" methods).  Interestingly, the exact same method <strong>does</strong> work if I pull it out into a separate class:</p>
  
  <pre><code>export class Utils {
      public static unsubscribeAll (subObject: {subscriptions: Subscription[]}) {
          subObject.subscriptions.forEach(subscription =&gt; subscription.unsubscribe())
      }
  }
  
  // ---------- back to the component
  
  ngOnDestroy () {
      Utils.unsubscribeAll({subscriptions: this.subscriptions}) // no Firebase errors
  }
  </code></pre>
  
  <p>but I don't really like this solution, mostly because it only works if I wrap the array in an object so it passes as a reference.  The other working method I found was to write it as a for loop:</p>
  
  <pre><code>ngOnDestroy () {
      /* tslint:disable */
      for (let i = 0; i &lt; this.subscriptions.length; i++) {
          this.subscriptions[i].unsubscribe()
      }
      /* tslint:enable */
  }
  </code></pre>
  
  <p>but aside from the unnecessary length, it also makes TSLint complain because it thinks I should be using a for-of loop instead (which doesn't work) so I have to throw in the extra comments every time.</p>
  
  <p>Currently I'm using the Utils option as the "best" solution, but I'm still not happy with it.  Is there a cleaner way to do this that I'm missing?</p>