title: JavaScript Set() with specific key to hash on
body: <p>I have a few objects that are all disparate, but which all have an <code>id</code> field. I want to create a Set() to hold these, but am not sure how to specify this field to the Set constructor/prototype/etc. Is this doable? </p>
  
  <p>Let's say I have two types of objects (I'll give typescript definitions for simplicity's sake): </p>
  
  <pre><code>interface Thing1 {
    id: string;
    someData: string[]
  }
  
  interface Thing2 {
    id: string;
    someString: string;
    someOtherString: string
  }
  </code></pre>
  
  <p>Now, I have two Arrays of these things, let's call them </p>
  
  <pre><code>array1: Thing1[];
  array2: Thing2[];
  </code></pre>
  
  <p>What I'd like to do is create a <code>new Set(array1)</code> and then <code>add</code> each <code>Thing2</code> in <code>array2</code>, performing a conditional merge of the two arrays. </p>
  
  <p>The unique key in each of these is the <code>id</code> field - I was hoping there was some overloaded constructor or similar pattern that could be given a lambda (a la <code>new Set(array1, (item) =&gt; item.id)</code>, maybe) which would specify the key to hash on for identity. </p>