title: Comparing 2 arrays of nested objects while ignoring some properties in Javascript
body: <p>I'm looking to check an API response for against a set of values but the API response contains some additional info that I'm not interested in checking against</p>
  <p>Data to check:</p>
  <pre><code>[
      {
          &quot;address&quot;: {
              &quot;city&quot;: &quot;London&quot;,
              &quot;firstLine&quot;: &quot;23 High Road&quot;,
              &quot;postCode&quot;: &quot;WC1 1AA&quot;,
              &quot;region&quot;: &quot;South East&quot;,
              &quot;uniqueIdentifier&quot;: 239
  
  
          },
          &quot;detail&quot;: {
              &quot;leaseholdFreehold&quot;: &quot;Freehold&quot;,
              &quot;location&quot;: &quot;Satisfactory&quot;,
              &quot;sector&quot;: &quot;Office&quot;
  
          },
          &quot;valuation&quot;: {
              &quot;value&quot;: &quot;770000&quot;,
              &quot;valuationDate&quot;: &quot;2018-03-07&quot;,
              &quot;yield&quot;: &quot;7.75&quot;
          }
      },
      {
          &quot;address&quot;: {
              &quot;city&quot;: &quot;Leeds&quot;,
              &quot;firstLinePropertyName&quot;: &quot;45 Headrow&quot;,
              &quot;postCode&quot;: &quot;LS2 8AA&quot;,
              &quot;region&quot;: &quot;North East&quot;,
              &quot;uniqueIdentifier&quot;: 287
          },
          &quot;detail&quot;: {
              &quot;leaseholdFreehold&quot;: &quot;Freehold&quot;,
              &quot;location&quot;: &quot;Good&quot;,
              &quot;sector&quot;: &quot;Residential&quot;
  
          },
          &quot;valuation&quot;: {
              &quot;value&quot;: &quot;88000&quot;,
              &quot;valuationDate&quot;: &quot;2018-03-07&quot;,
              &quot;yield&quot;: &quot;8.87&quot;
          }
      }
  ]
  </code></pre>
  <p>API response:</p>
  <pre><code>[
          {
              &quot;address&quot;: {
                  &quot;city&quot;: &quot;London&quot;,
                  &quot;firstLine&quot;: &quot;23 High Road&quot;,
                  &quot;postCode&quot;: &quot;WC1 1AA&quot;,
                  &quot;region&quot;: &quot;South East&quot;,
                  &quot;uniqueIdentifier&quot;: 239
              },
              &quot;detail&quot;: {
                  &quot;designAndCondition&quot;: &quot;&quot;,
                  &quot;developmentCompletionDate&quot;: &quot;0001-01-01&quot;,
                  &quot;leaseholdFreehold&quot;: &quot;Freehold&quot;,
                  &quot;location&quot;: &quot;Satisfactory&quot;,
                  &quot;sector&quot;: &quot;Office&quot;
  
              },
              &quot;valuation&quot;: {
                  &quot;value&quot;: &quot;770000&quot;,
                  &quot;valuationDate&quot;: &quot;2018-03-07&quot;,
                  &quot;yield&quot;: &quot;7.75&quot;
              },
              &quot;dbIdentifier&quot;: 240
          },
          {
              &quot;address&quot;: {
                  &quot;city&quot;: &quot;Leeds&quot;,
                  &quot;firstLinePropertyName&quot;: &quot;11 Main Road&quot;,
                  &quot;postCode&quot;: &quot;LS2 8AA&quot;,
                  &quot;region&quot;: &quot;North East&quot;,
                  &quot;uniqueIdentifier&quot;: 282
              },
              &quot;detail&quot;: {
                  &quot;designAndCondition&quot;: &quot;&quot;,
                  &quot;developmentCompletionDate&quot;: &quot;0001-01-01&quot;,
                  &quot;leaseholdFreehold&quot;: &quot;Freehold&quot;,
                  &quot;location&quot;: &quot;Good&quot;,
                  &quot;sector&quot;: &quot;Residential&quot;
  
              },
              &quot;valuation&quot;: {
                  &quot;value&quot;: &quot;88000&quot;,
                  &quot;valuationDate&quot;: &quot;2018-03-07&quot;,
                  &quot;yield&quot;: &quot;8.75&quot;
              },
              &quot;dbIdentifier&quot;: 239
          }
  ]
  </code></pre>
  <p>So I'm not interested in what values are returned for <code>dbIdentifier</code>, <code>designAndCondition</code> and  <code>developmentCompletionDate</code> as they are not in my data to check against but I would like to compare the values for the rest of the properties. In practice these arrays will have more than 2 items</p>
  <p>I was initially thinking I would remove the unwanted properties from the objects using the function below</p>
  <pre><code>const newArray = responseBody.map(({ dbIdentifierIdentifier, detail: { designAndCondition, developmentCompletionDate  }, ...rest }) =&gt; rest)
  </code></pre>
  <p>Then ordering by <code>address.uniqueIdentifier</code>, converting to JSON strings and comparing the strings but the function above doesn't work with the nested properties as <code>newArray</code> doesn't contain the <code>detail</code> object at all</p>
  <p><code>newArray</code>:</p>
  <pre><code>[
          {
              &quot;address&quot;: {
                  &quot;city&quot;: &quot;London&quot;,
                  &quot;firstLine&quot;: &quot;23 High Road&quot;,
                  &quot;postCode&quot;: &quot;WC1 1AA&quot;,
                  &quot;region&quot;: &quot;South East&quot;,
                  &quot;uniqueIdentifier&quot;: 239
              },
              &quot;valuation&quot;: {
                  &quot;value&quot;: &quot;770000&quot;,
                  &quot;valuationDate&quot;: &quot;2018-03-07&quot;,
                  &quot;yield&quot;: &quot;7.75&quot;
              },
              &quot;dbIdentifier&quot;: 240
          },
          {
              &quot;address&quot;: {
                  &quot;city&quot;: &quot;Leeds&quot;,
                  &quot;firstLinePropertyName&quot;: &quot;11 Main Road&quot;,
                  &quot;postCode&quot;: &quot;LS2 8AA&quot;,
                  &quot;region&quot;: &quot;North East&quot;,
                  &quot;uniqueIdentifier&quot;: 282
              },
              &quot;valuation&quot;: {
                  &quot;value&quot;: &quot;88000&quot;,
                  &quot;valuationDate&quot;: &quot;2018-03-07&quot;,
                  &quot;yield&quot;: &quot;8.75&quot;
              },
              &quot;dbIdentifier&quot;: 239
          }
  ]
  </code></pre>
  <p>IS it possible to do it the above way by passing a destructured nested object a map function?</p>