title: Mapping array to object using spread
body: <p>I would like to transform the follow array into a slightly modified object (see below). I'm also trying to practice using the spread operator, but haven't been able to figure out how to do it. I'm trying to avoid using lodash (for educational purposes).</p>
  
  <p>Starting array:</p>
  
  <pre><code>var arr = [
      { mainkey: 'John', val1: 'ABC', val2: '..', val3: '..' },
      { mainkey: 'Mary', val1: 'DEF', val2: '..', val3: '..' },
      { mainkey: 'Ann', val1: 'XYZ', val2: '..', val3: '..' }
    ];
  </code></pre>
  
  <p>to final object:</p>
  
  <pre><code>newObj = {
    John: {val1: 'ABC', val2: '..', val3: '..' },
    Mary: {val1: 'DEF', val2: '..', val3: '..' },
    Ann:  {val1: 'XYZ', val2: '..', val3: '..' }
  }
  </code></pre>
  
  <p>Without using the spread operator, this gets close, but not where I need to be:</p>
  
  <pre><code>var result = arr.reduce(function(map, obj) {
      map[obj.mainkey] = obj.val1;
      // map[obj.mainkey] = { obj.val1, obj.val2 }; &lt;-- DOESNT WORK
      return map;
  }, {});
  </code></pre>
  
  <p>With the spread operator anything I do fails.</p>
  
  <p>Other posts with helpful content:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/q/38228988/7388644">React object spread (ES6) returned from map</a></li>
  <li><a href="https://stackoverflow.com/q/26264956/7388644">Convert object array to hash map, indexed by an attribute value of the Object</a></li>
  </ul>