Indagamos por el mundo online para de este modo traerte la solución a tu duda, en caso de alguna pregunta puedes dejarnos tu pregunta y responderemos con gusto, porque estamos para servirte.
Ejemplo 1: intersección de dos objetos en javascript
var firstObject =
x:0,
y:1,
z:2,
a:10,
b:20,
e:30var secondObject =
x:0,
y:1,
z:2,
a:10,
c:20,
d:30functiongetIntKeys(obj1, obj2)var k1 =Object.keys(obj1);return k1.filter(function(x)return obj2[x]!==undefined;);alert(getIntKeys(firstObject, secondObject));
Ejemplo 2: intersección de dos objetos profundos en 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'constgetDifference=(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)returnObject.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)
Tienes la posibilidad compartir esta división si te fue de ayuda.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)