I'm trying to merge duplicate objects in a json array I received.
The array looks like this:
{
modules: [{
"name": "Weazel",
"otherprop": ["a", "b"]
}, {
"name": "weazel",
"otherprop": ["c", "b"]
}]
}
For some reason I can't figure out how to merge the duplicates.
I have tried doing it by first mapping all the names to lowercase and then use unique, but that removes the values for otherprops.
let result = _.map(json.modules, mod => { mod.name = mod.name.tolower(); return mod; });
result = _.unique(result, 'name');
Is there anyone who knows how I can tackle my issue using lodash?
otherpropshould be after your merge.['a','b','c']?['a','b','c','b']?