title: JavaScript Reduce Array of objects to object dictionary
body: <p>I've read this <a href="https://stackoverflow.com/questions/5732043/javascript-reduce-on-array-of-objects">answer</a> on SO to try and understand where I'm going wrong, but not quite getting there.</p>
  
  <p>I have this function :</p>
  
  <pre><code>get() {
      var result = {};
  
      this.filters.forEach(filter =&gt; result[filter.name] = filter.value);
  
      return result;
  }
  </code></pre>
  
  <p>It turns this :</p>
  
  <pre><code>[
      { name: "Some", value: "20160608" }
  ]
  </code></pre>
  
  <p>To this :</p>
  
  <pre><code>{ Some: "20160608" }
  </code></pre>
  
  <p>And I thought, that is exactly what <code>reduce</code> is for, I have an array, and I want one single value at the end of it.</p>
  
  <p>So I thought this :</p>
  
  <pre><code>this.filters.reduce((result, filter) =&gt; {
      result[filter.name] = filter.value;
      return result;
  });
  </code></pre>
  
  <p>But that doesn't produce the correct result.</p>
  
  <blockquote>
    <p>1) Can I use Reduce here?</p>
    
    <p>2) Why does it not produce the correct result.</p>
  </blockquote>
  
  <p>From my understanding, the first iteration the result would be an empty object of some description, but it is the array itself.</p>
  
  <p>So how would you go about redefining that on the first iteration - these thoughts provoke the feeling that it isn't right in this situation!</p>