title: Reduce array to object using arrow function
body: <p>I'm playing around with the limits of array and arrow functions and I'm trying to convert this reduce function into an arrow function:</p>
  
  <pre><code>var monthsById = months.reduce(function(result, month) {
                              result[month.Id] = month;
                              return result;
                          }, {});
  </code></pre>
  
  <p>But I'm having trouble to return the map, since <code>result[month.Id] = month;</code> will return the month and not the map like in this approach:</p>
  
  <pre><code>var monthsById = months.reduce((byId, month) =&gt; byId[month.Id] = month, {});
  </code></pre>
  
  <p>So I'm looking for a single statement, that sets the value AND returns the object. (<code>new Map()</code> is not an option, since I need it in the regular <code>{}</code> format).</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var months = [ { Id: 1 }, { Id: 2 }, { Id: 3 } ];
  
  var monthsById = months.reduce((byId, month) =&gt; byId[month.Id] = month, {});
  
  console.log(monthsById);</code></pre>
  </div>
  </div>
  </p>