title: Javascript Map has duplicate keys
body: <p>The Map object <code>set</code> method is meant to add a new key/pair, or update an existing key/pair. <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set" rel="nofollow">See docs</a>.</p>
  
  <p>I've been struggling to figure out how it is that my Map has ended up with duplicate keys when I attempt to populate it with database results:</p>
  
  <pre><code>let users = new Map();
  
  function loadUserByName(name) {
      db.loadUser({ name }, (err, user) =&gt; {
          users.set(user.id, user);          
      });
  }
  
  loadUser('george');
  users.forEach( (item) =&gt; { console.log(item.key); } );
  // Output:
  // 57bbfcb47ff30b00db69ae87
  
  loadUser('george');
  users.forEach( (item) =&gt; { console.log(item.key); } );
  // Output:
  // 57bbfcb47ff30b00db69ae87
  // 57bbfcb47ff30b00db69ae87
  </code></pre>