I have two arrays like below:
var oldArray = [{ id: '10', name: 'ABC', type: 'type1' },
{ id: '11', name: 'XYZ', type: 'type1' }]
var newArray=[{ id: '10', name: 'ABC', type: 'type1' },
{ id: '11', name: 'XYZ', type: 'type1' }
{ id: '12', name: 'PQR', type: 'type1' },
{ id: '13', name: 'SomeNewData', type: 'type2' }]
I want to get that PQR object from the newArray because it is of type1 and the only object which is difference in the oldArray and push that object into oldArray.
I tried it using the difference method of lodash but I couldn't get it done. Can I achieve this using lodash? Any solution using native JavaScript will also be useful.
Any help would be much appreciated. Thanks!
newArraythat are not inoldArray? Or do you want even elements inoldArraythat are not innewArray?SomeNewDataI won't need this because it is oftype2. I only need the difference between those oftype1.PQRobject with less and meaningful code usingLodash.