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

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -