JSFiddle - React, Tailwind, and code Playground
HTML
<head>
<script src="https://cdn.jsdelivr.net/lodash/4.13.1/lodash.min.js"></script>
</head>
<body>
</body>
JavaScript
const input1 = [{
componentId: "ExchangeCurrency",
componentModel: {
"CurrencyRate": 0.021362956633198035,
"DebitAccount": null,
"CreditAccount": null,
"PurchaseAmount": "42.73",
"PaymentAmount": "2000",
"CommissionResult": {}
}
}];
const input2 = [{
componentId: "ExchangeCurrency",
componentModel: {
"CurrencyRate": 0.0,
"DebitAccount": {
"AccountId": 134118,
"TypeId": 64,
"CardId": 64531,
"CurrencyId": 22,
"CardPaymentSystemTypeId": 1523,
"Label": "Зарплатная++",
"AvailableOwnFunds": 111105.83,
"Overdraft": 500000.0,
"IsPaymentFromCard": true,
"ContractId": 233,
"AccountCloseDate": "0001-01-01T00:00:00"
},
"PurchaseAmount": 0.0,
"PaymentAmount": 0.0,
"CreditAccount": null,
"CommissionResult": null,
"PaymentReason": null
}
}];
const expectedResult = [{
componentId: "ExchangeCurrency",
componentModel: {
"CurrencyRate": 0.021362956633198035,
"DebitAccount": {
"AccountId": 134118,
"TypeId": 64,
"CardId": 64531,
"CurrencyId": 22,
"CardPaymentSystemTypeId": 1523,
"Label": "Зарплатная++",
"AvailableOwnFunds": 111105.83,
"Overdraft": 500000.0,
"IsPaymentFromCard": true,
"ContractId": 233,
"AccountCloseDate": "0001-01-01T00:00:00"
},
"PurchaseAmount": "42.73",
"PaymentAmount": "2000",
"CreditAccount": null,
"CommissionResult": {},
"PaymentReason": null
}
}];
const actualResult = Array({ ...input2[0], componentModel: _.assignWith({}, input2[0].componentModel, input1[0].componentModel, (t, s) => t ? t : s)})
console.log(actualResult)
console.log(_.isEqual(expectedResult, actualResult));