title: KO: Is it bad form to iterate through observable arrays with ko utility methods?
body: <p>From <a href="https://stackoverflow.com/a/9077264/109941">this post</a>:</p>
  
  <blockquote>
    <p>I would first suggest that you optimize your <code>dependentObservable</code> (a.k.a. <code>computed</code>). When
    you read any observable, Knockout registers a dependency to it in
    Dependency Manager...</p>
    
    <p>I can see in your pseudo-code that you are accessing this.ParentList()
    in the while loop. It means registerDependency will be called 3000
    times and the dependencies array will be scanned 3000 times, which is
    bad for IE (since it has no built-in Array.indexOf method).</p>
    
    <p>So my number one suggestion would be: <strong>Read all observables before
    loops.</strong></p>
  </blockquote>
  
  <p>With this good advice in mind, here's my question:</p>
  
  <p>Is it bad form to iterate through <code>observable</code> arrays with ko utility methods (like the following)? [assume that <code>this.mySelectListItems()</code> is an <code>observableArray</code>]:</p>
  
  <pre><code>self.selectedValuesCount = ko.computed(function () {
      var total = 0;
      ko.utils.arrayForEach(this.mySelectListItems(), function (item) {
          if (item.selected() === true) {
              total += 1;
          }
      });
      return total;
  }, self);
  </code></pre>
  
  <p>In other words, is there anything to be gained by doing the following?</p>
  
  <pre><code>self.selectedValuesCount = ko.computed(function () {
      var total = 0;
      var myArray = this.mySelectListItems();
      ko.utils.arrayForEach(myArray, function (item) {
          if (item.selected() === true) {
              total += 1;
          }
      });
      return total;
  }, self);
  </code></pre>