title: Javascript - reduce to an object
body: <p>Execute below code in chrome console - for the google page.</p>
  
  <pre><code>[].slice.call(document.querySelectorAll("input"))
                         .map(el =&gt; el.name?el.name:el.id)
  </code></pre>
  
  <p>I see this output.</p>
  
  <p><a href="https://i.stack.imgur.com/dQZBA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dQZBA.png" alt="enter image description here"></a></p>
  
  <p>I wanted to reduce this list to an object.</p>
  
  <pre><code>         .reduce((acc,el) =&gt; acc[el] = el.toUpperCase(), {});
  </code></pre>
  
  <p>I expected something like below...</p>
  
  <pre><code>            {
                  "sclient":"SCLIENT",
                  "site":"SITE",
                  ...
              }
  </code></pre>
  
  <p>But it returns only the last element.</p>
  
  <p><a href="https://i.stack.imgur.com/UNpOu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UNpOu.png" alt="enter image description here"></a></p>
  
  <p>What is wrong with this reduce function?</p>