title: Looping through array to add ko.computed to each object
body: <p>I'm passing my viewmodel from the server as JSON, then adding some functions and observables to the viewmodel before calling <code>ko.applyBindings()</code>.</p>
  
  <p>My problem is that I want to loop through an array of objects, and add a computed observable onto each. However, all the computed observables seem to be bound to the last object in my array.</p>
  
  <p>Here is the loop:</p>
  
  <pre><code>for (var i = 0; i &lt; viewModel.Records().length; i++)
  {
      var record = viewModel.Records()[i];
  
      viewModel.Records()[i].CachedMonthlyAmount = ko.computed(function () {
          var frequencyType = viewModel.GetFrequencyTypeByID(record.SelectedFrequencyTypeID());
          return frequencyType.MonthlyCalculationFactor() * record.Amount();
      });
  }
  </code></pre>
  
  <p>I've also created <a href="http://jsfiddle.net/952pfm61/1/" rel="nofollow">this jsfiddle</a> to demonstrate.</p>