title: JS - merge 2 arrays based on properties
body: <p>I'm trying to merge 2 arrays of objects where the resulting array should have only objects present in array 1 (selectedNames) but with one property from corresponding objects from array 2 (nameDetails). There's one matching (unique) property to match them:</p>
  <pre><code>const selectedNames = [
    {
      id: '11'
      name: 'joe',
    },
    {
      id: '22',
      name: 'bill',
    },
  ];
  
  const nameDetails = [
    {
      nameId: '11',
      salary: '23422',
      location: 'New Jersey',
    },
    {
      nameId: '33',
      salary: '23424',
      location: 'New York',
    },
    {
      nameId: '22',
      salary: '99999',
      location: 'Boston',
    },
    { nameId: '44',
      salary: '323232',
      location: 'Chicago',
    },
  ];
  </code></pre>
  <p>The matching property is selectedNames.id === nameDetails.nameId. All entries in selectedNames will definitely be present in nameDetails (but not the other way round). The resulting array should look like that:</p>
  <pre><code>[
    {
      id: '11',
      name: 'joe',
      salary: '23422',
    },
    {
      id: '22',
      name: 'bill',
      salary: '99999'
    }
  ]
  </code></pre>
  <p>I'm a bit confused. I know it'll probably consist of .includes() and filter() and ... for merging? I'm not sure how to handle it.</p>
  <p>Alternatively, which will probably be much easier, filter the nameDetails array to have only objects with nameId that exists (as id) in selectedNames.</p>