I have two arrays originalArray
and modifiedArray
which have objects with some properties; sys_id
is the unique property:
originalArray = [
{ sys_id: 1234, type: 'XYZZ' },
{ sys_id: 1235, type: 'ABCD' },
{ sys_id: 1236, type: 'IJKL' },
{ sys_id: 1237, type: 'WXYZ' },
{ sys_id: 1238, type: 'LMNO' }
]
modifiedArray = [
{ sys_id: 1234, type: 'XYZZ' },
{ sys_id: 1235, type: 'ZZAA' },
{ sys_id: 1236, type: 'ZZZZ' },
{ sys_id: 1252, type: 'AAAA' }
]
I'm looking to combine/merge the arrays but include a new property that describes a full account of what changed in the new array based on the original array using the sys_id property.
resultingArray = [
{ sys_id: 1234, type: 'XYZZ', action: 'same' },
{ sys_id: 1235, type: 'ZZAA', action: 'edit' },
{ sys_id: 1236, type: 'ZZZZ', action: 'edit' },
{ sys_id: 1237, type: 'WXYZ', action: 'remove' },
{ sys_id: 1238, type: 'LMNO', action: 'remove' },
{ sys_id: 1252, type: 'AAAA', action: 'add' }
Also would like to know if there is more proper terminology, or a more concise way to explain what I'm trying to accomplish here?
I'm on a platform that is limited to ES5.