Intersection of two deep objects in JavaScript code example

Example: Intersection of two deep objects in JavaScript

const company = {
    lastYearRevenue: 4444,
    capacityInstalled: 22,
    ppaDemands: [ 'f6202f82501ee7350cc73fd', '5f6211ef0b5983761f4d0bb8' ],
    activeProjects: [
      '5f6204162501ee7350cc7406',
      'f6207462501ee7350cc7408',
      '5f62411e21a66a8a5ca6d51f'
    ],
    companyGroup: 'kjkj',
    invoicingAddress: '',
    businessAddress: 'jk',
    legalEntityVatNumber: 'kjkj',
    legalEntity: 'jkj',
    balancingPartyBiddingZones: [
      {
        key: 'balancingPartyBiddingZones',
        value: 'Albania',
        label: 'Albania'
      },
      {
        key: 'balancingPartyBiddingZones',
        value: 'Barbados',
        label: 'Barbados'
      }
    ],
    tradingLicenseBiddingZones: [
      {
        key: 'tradingLicenseBiddingZones',
        value: 'Albania',
        label: 'Albania'
      },
      {
        key: 'tradingLicenseBiddingZones',
        value: 'Barbados',
        label: 'Barbados'
      }
    ],
    isABalancingParty: 'Yes',
    hasTradingLicense: 'Yes',
    ableToProvideFirming: 'Yes',
    leaveNamingRights: 'Yes',
    provideAnotherStructure: '',
    tradingLicense: '1111',
    requireNamingRights: 'Yes',
    signedPpaBefore: 'No',
    parentCompanyGuarantee: 'No',
    offerInvestmentGrade: 'Yes',
    structureProposed: '',
    regionPresent: '',
    creditRating: ' 1111',
    acceptSellersTerms: '',
    historyOfPpa: [],
    favourites: [],
    cleanBuyersAssociation: 'RE100',
    linkToCompany: '',
    signedPpaMarketing: '',
    acceptBuyersTerms: '',
    twoYearPipeline: 22,
    willingToAggregate: 'Yes',
    targetReached: '2034',
    amountOfEnergyBuying: '',
    procurementTarget: '98',
    locations: [],
    energy: [],
    sector: 'Agriculture',
    companyName: '',
    users: [ '5e6f76572097e12186c46e4b' ],
    profileType: '',
    email: '',
    userName: ''
  }

const payload =   { cleanBuyersAssociation: 'RE00' } 

  const getDifference = (a, b) => {
    const entries = Object.entries(b)
    const filteredEntries = Object.entries(b).filter(([key, val]) => key in a )
    console.log(entries)
    console.log('Object.fromEntries(entries) = ', Object.fromEntries(entries))
    console.log('filteredEntries = ', filteredEntries)
    console.log('Object.fromEntries(filteredEntries) = ', Object.fromEntries(filteredEntries))
    // Object.entries(b)
    return Object.fromEntries(Object.entries(b).filter(([key, val]) => {
      return key in a
      // && a[key] !== val
    }))
  }
  
   const toReturn = getDifference(payload, company)

console.log('toReturn: ', toReturn)

    const entries = Object.entries(company)
    console.log(entries)

getDifference(payload, company)