title: Extracting unique values from an array of objects where value is a nested object in JavaScript
body: <p>Let's say I've got the following array of objects in JavaScript:</p>
  
  <pre class="lang-js prettyprint-override"><code>const requests = [
    {
      id: 1,
      person: {
        id: 1
      }
    },
    {
      id: 2,
      person: {
        id: 1
      }
    },
    {
      id: 3,
      person: {
        id: 2
      }
    },
    {
      id: 4,
      person: {
        id: 3
      }
    },
    {
      id: 5,
      person: {
        id: 2
      }
    }
  ]
  </code></pre>
  
  <p>And what I've written below will go over each item in the array, and then create a new array containing just the <code>person</code> object.</p>
  
  <pre class="lang-js prettyprint-override"><code>const requestsPeopleIds = []
  for (const request of requests) {
    requestsPeopleIds.push(request.person.id)
  }
  </code></pre>
  
  <p>I then take that new array and create another new array using <code>Set</code> to remove the duplicate <code>id</code>s:</p>
  
  <pre class="lang-js prettyprint-override"><code>const uniquePeopleIds = Array.from(new Set(requestsPeopleIds))
  </code></pre>
  
  <p>The final result is as I'd expect:</p>
  
  <pre class="lang-js prettyprint-override"><code>console.log(uniquePeopleIds) // [1, 2, 3]
  </code></pre>
  
  <p>where these are the unique <code>id</code>s of the people who made a request. So out of the <code>5</code> requests, these were made by <code>3</code> people.</p>
  
  <p>There must be a more efficient way of doing this, so I'm reaching out to you <code>stack overflow</code> JS gurus.</p>
  
  <p>Thanks in advance.</p>