javascript - Merge duplicate objects in single array using lodash -
i'm trying merge duplicate objects in json array received.
the array looks this:
{ modules: [{ "name": "weazel", "otherprop": ["a", "b"] }, { "name": "weazel", "otherprop": ["c", "b"] }] }
for reason can't figure out how merge duplicates.
i have tried doing first mapping names lowercase , use unique, removes values otherprops.
let result = _.map(json.modules, mod => { mod.name = mod.name.tolower(); return mod; }); result = _.unique(result, 'name');
is there knows how can tackle issue using lodash?
var result = _.uniq(json.modules, function(item, key, a) { return item.a; }); //result : [{"name":"weazel","otherprop":["a","b"]}]
Comments
Post a Comment