title: JavaScript reduce not working on an object
body: <p>I am trying to understand how reduce works</p>
  <pre class="lang-js prettyprint-override"><code>var expense = [
      {
          item: &quot;Bed&quot;,
          cost: 1499,
          date: &quot;02-23-2018&quot;
      },
      {
          item: &quot;Phone&quot;,
          cost: 2499,
          date: &quot;02-23-2018&quot;
      },
      {
          item: &quot;Book&quot;,
          cost: 400,
          date: &quot;02-23-2018&quot;
      },
      {
          item: &quot;Mattress&quot;,
          cost: 700,
          date: &quot;02-23-2018&quot;
      },
      {
          item: &quot;Food&quot;,
          cost: 300,
          date: &quot;02-23-2018&quot;
      }
  ];
  
  var totalExpense = expense.reduce(function (a, b) {
      console.log(a.cost, b.cost);
      return a.cost + b.cost;
  });
  
  console.log(totalExpense);
  </code></pre>
  <p>this gives totalExpense as <code>NaN</code>.</p>
  <p>Output:</p>
  <pre><code>1499 2499
  undefined 400
  undefined 700
  undefined 300
  NaN
  </code></pre>
  <p>When I perform the same operation with a simple expense array, it works fine.</p>