title: Sum numbers from list in node.js
body: <p>I have just started learning node.js. 
  I am trying to create a script that will get a list from a file. The list is built like this</p>
  
  <pre><code>Bob:110
  Mike:120
  Bob:334
  Dan:240
  </code></pre>
  
  <p>And will give this output </p>
  
  <pre><code>name value
  </code></pre>
  
  <p>It is supposed to sum the numbers associated with the same name.</p>
  
  <p>So in my example it would print</p>
  
  <pre><code>Bob 444
  Mike 120
  Dan 240
  </code></pre>
  
  <p>I used the help I found in this site to create some basic script</p>
  
  <pre><code>fs = require('fs');
  var array = fs.readFileSync('C:\\data.txt').toString().split("\n");
  
  var items = {}, base, key;
  for (var i = 0; i &lt; array.length; i++) {
      base = array[i];
      key = base[0];
      if (!items[key]) {
          items[key] = 0;
      }
      items[key] += base[1];
  }
  
  var outputArr = [], temp;
  for (key in items) {
      temp = [key, items[key]]
      outputArr.push(temp);
  }
  console.log(outputArr);
  </code></pre>
  
  <p>Notice that I get the list from a text file, but it currently contains what I have posted in this question.
  The output that I get is very gibberishy, and I am not sure why.
  This is my output:</p>
  
  <pre><code>[ [ 'B', '0oo' ],
    [ 'M', '0i' ],
    [ 'D', '0a' ],
    [ 'undefined', NaN ] ]
  </code></pre>
  
  <p>Can anyone please help me understand why this does not work properly and show me how to fix it?</p>
  
  <p>By the way, I am not certain if this is the correct thought line for accomplishing such a task in node.js. I would be happy to get feedback!</p>
  
  <p>Thanks a lot!</p>