I have two arrays:
arr1 = [
{
"OwnershipNumber": 0,
"ID": null,
"Name": "Contractor LLC",
"ContrEmployeeTypeId": 0,
"ContactEmail": "",
"ContactPhone": "",
"VeteranEmployeeMilitaryAffiliation": "",
"SocialSecurityNumber": "",
"DrivingLicense": "",
"DateOfBirth": null,
"OwnershipPercentage": 0,
"IsContractorActive": "Y",
"VeteranFlag": "N",
"VeteranEmployeeHireDate": null,
"LegalIssueFlag": "N",
"ActiveFlag": true,
"TimeStamp": null
},
{
"OwnershipNumber": 1878,
"ID": null,
"Name": "Greg Dawson",
"ContrEmployeeTypeId": 2,
"ContactEmail": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="52222033123330317c313d3f">[email protected]</a>",
"ContactPhone": "455-455-6444",
"VeteranEmployeeMilitaryAffiliation": null,
"SocialSecurityNumber": "454534245",
"DrivingLicense": "44524245",
"DateOfBirth": "11/30/1968 12:00:00 AM",
"OwnershipPercentage": 100,
"IsContractorActive": "Y",
"VeteranFlag": "N",
"VeteranEmployeeHireDate": null,
"LegalIssueFlag": "N",
"ActiveFlag": true,
"TimeStamp": null
}
]
arr 2 = [ {"OwnershipNumber": 1878, "ContactPhone": "111-222-6444"},
{
"OwnershipNumber": null,
"ID": 3,
"SocialSecurityNumber": "465464654",
"DrivingLicense": "464654654654",
"DateOfBirth": "1998-12-12T18:30:00.000Z",
"VeteranEmployeeHireDate": "1970-01-01T00:00:00.000Z",
"Name": "Tom Hanks",
"ContrEmployeeTypeId": 1,
"IsContractor": "N",
"ContactEmail": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="43372c2e03242e222a2f6d202c2e">[email protected]</a>",
"ContactPhone": "564-465-4654",
"OwnershipPercentage": 100
}
]
I am trying to accomplish this after merging and pushing:
arr3 = [
{
"OwnershipNumber": 0,
"ID": null,
"Name": "Contractor LLC",
"ContrEmployeeTypeId": 0,
"ContactEmail": "",
"ContactPhone": "",
"VeteranEmployeeMilitaryAffiliation": "",
"SocialSecurityNumber": "",
"DrivingLicense": "",
"DateOfBirth": null,
"OwnershipPercentage": 0,
"IsContractorActive": "Y",
"VeteranFlag": "N",
"VeteranEmployeeHireDate": null,
"LegalIssueFlag": "N",
"ActiveFlag": true,
"TimeStamp": null
},
{
"OwnershipNumber": 1878,
"ID": null,
"Name": "Greg Dawson",
"ContrEmployeeTypeId": 2,
"ContactEmail": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b1c1c3d0f1d0d3d29fd2dedc">[email protected]</a>",
"ContactPhone": "111-222-6444",
"VeteranEmployeeMilitaryAffiliation": null,
"SocialSecurityNumber": "454534245",
"DrivingLicense": "44524245",
"DateOfBirth": "11/30/1968 12:00:00 AM",
"OwnershipPercentage": 100,
"IsContractorActive": "Y",
"VeteranFlag": "N",
"VeteranEmployeeHireDate": null,
"LegalIssueFlag": "N",
"ActiveFlag": true,
"TimeStamp": null
},
{
"OwnershipNumber": null,
"ID": 3,
"SocialSecurityNumber": "465464654",
"DrivingLicense": "464654654654",
"DateOfBirth": "1998-12-12T18:30:00.000Z",
"VeteranEmployeeHireDate": "1970-01-01T00:00:00.000Z",
"Name": "Tom Smith",
"ContrEmployeeTypeId": 1,
"IsContractor": "N",
"ContactEmail": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cebaa1a38ea9a3afa7a2e0ada1a3">[email protected]</a>",
"ContactPhone": "564-465-4654",
"OwnershipPercentage": 100
}
]
The first array (arr1) serves as the master array, while the second array (arr2) contains only the changes that have been made in relation to the first array. For example, you can see that ownership number 1878 has a change in the ContactPhone field. Therefore, ContactPhone along with OwnershipNumber is present in arr2. It can also include a new object like the one with the name field Tom Smith (which does not exist in arr1). The goal is to merge the changes based on the OwnershipNumber and ContactEmail, and add any new elements like the object with the name field Tom Smith into the new array (arr3). The changes and inclusion of new elements are optional, so arr2 may be blank. Your assistance with this would be greatly appreciated.