I have 2 arrays, and I want a new array based upon condition that the content of these 2 arrays matched
arr1 = [{
package_id: 'aabbccdd',
level: 2
},
{
package_id: 'xycd21',
level: 3
}
]
arr2 = [{
package_id: 'aabbccdd',
level: 1
},
{
package_id: 'zcb21',
level: 5
}]
mergedArray = [{
package_id: 'aabbccdd',
arr1Level: 2,
arr2Level: 1
},
{
package_id: 'xycd21',
arr1Level: 3,
arr2Level: 0
},
{
package_id: 'zcb21',
arr1Level: 0,
arr2Level: 5
}]
So if package_id is to be checked in both arrays. And if found in either array, new array pushed one element where level from both array is mentioned against package_id.
I just could not figure out the logic to do that. If that can be done by lodash kindly tell me.