title: Knockout add item to each of the observable array
body: <p>I have a function and this is the code:</p>
  
  <pre><code>this.federalPriceComputed = ko.pureComputed(
          function() {
              return ko.utils.arrayMap(this.lineItems(), function(item) {
                  var total = item.price() * item.federalTax()
                  return formatCurrency(total);
              });
          }, this
      ).extend({ throttle: 500 });
  
  this.statePriceComputed = ko.pureComputed(
              function() {
                  return ko.utils.arrayMap(this.lineItems(), function(item) {
                      var total = item.price() * item.stateTax()
                      return formatCurrency(total);
                  });
              }, this
          ).extend({ throttle: 500 });
  </code></pre>
  
  <p>When i run my code it says <code>statePriceComputed is not defined</code>. </p>
  
  <p>I am trying to keep all my code inside the model object. </p>
  
  <p>If I do this, it works.</p>
  
  <pre><code>ko.utils.arrayForEach(myModel.lineItems(), function(item) {
     item.federalPriceComputed = ...
     item.statePriceComputed = .... 
     }
  );
  </code></pre>
  
  <p>More information: </p>
  
  <pre><code>ko.observableArray.fn.withIndex = function (keyName) {  
      "use strict";
      var index = ko.computed(function () {
          var list, keys;
          list = this() || [];    // the internal array
          keys = {};              // a place for key/value
          ko.utils.arrayForEach(list, function (v) {
              if (keyName) {          // if there is a key
                  keys[ko.utils.unwrapObservable(v[keyName])] = v;    // use it
              } else {
                  keys[v] = v;
              }
          });
          return keys;
      }, this);
  
      // also add a handy add on function to find
      // by key ... uses a closure to access the 
      // index function created above
      this.findByKey = function (key) {
          return index()[key];
      };
  
      return this;
  };
  </code></pre>
  
  <p>When i bind the variable i did it like this</p>
  
  <pre><code>    if (stateTax.length) {
         stateTax.attr("data-bind", "text: formatCurrency($data.lineItems.findByKey(\"" + itemId + "\").statePriceComputed())");
      }
  
  // similar code for federal tax
  </code></pre>
  
  <p>Can you give suggestion why option #1 does not work. </p>