title: Returning Objects with JavaScript Reduce
body: <p>On FreeCodeCamp, I was introduced to this snippet of code:</p>
  <pre><code>const users = [
    { name: 'John', age: 34 },
    { name: 'Amy', age: 20 },
    { name: 'camperCat', age: 10 }
  ];
  
  const usersObj = users.reduce((obj, user) =&gt; {
    obj[user.name] = user.age;
    return obj;
  }, {});
  console.log(usersObj);
  
  // expected result : { John: 34, Amy: 20, camperCat: 10 }
  </code></pre>
  <p>I've been looking at this for a while now and just can't wrap my head around how the reduce function works here. In my view it works as follows in the first iteration:</p>
  <pre><code>**ITERATION 1:**
  Initial Accumulator (obj): {}
  CurrVal (user): {name: 'John', age: 34}
  Updated Accumulator: {}[{name: 'John', age: 34}.name] = {name: 'John', age: 34}.age;
  </code></pre>
  <p>But immediately there, it goes wrong in my console when trying this step by step, as I understand the Updated Accumulator is basically saying <code>[&quot;John&quot;] = 34</code> Why are we setting the name equal to the age?</p>
  <p>What am I missing here to connect the missing pieces? Why does the above code work?</p>