I have an array of objects that can contain duplicates, but I'd like uniquify the array by a property, and then I want to merge properties of the duplicates conditionally. For example, give the array below
var array = [
{
name: 'object1',
propertyA: true,
propertyB: false,
propertyC: false
},
{
name: 'object2',
propertyA: false,
propertyB: true,
propertyC: false
},
{
name: 'object1',
propertyA: false,
propertyB: true,
propertyC: false
}
]
Knowing each object has name, propertyA, propertyB, and propertyC, I'd like to uniquify by the name property, and keep the true values for propertyA, propertyB, and propertyC. So the above array becomes,
var updatedArray = [
{
name: 'object1',
propertyA: true,
propertyB: true,
propertyC: false
},
{
name: 'object2',
propertyA: false,
propertyB: true,
propertyC: false
}
]
What is the best way to go about this using lodash/underscore?