I have an array of objects:
var test = [{name: 'lorem', age: 20, color:'red'}, {name: 'lorem', weight: 1, height:5} , {name: 'hello', ipsum : 'dolor'}]
I would like to merge and group them. Expected result is:
var test = [{name: 'lorem', age : 20, color: 'red', weight : 1, height : 5}, {name: 'hello', ipsum : 'dolor'}]
Solution can be in vanilla, lodash or JQuery ...
EDIT: Sorry guys, I forgot to say that it has to be written in ES5
EDIT: I almost rewrote gorak's propostion to ES5. I tried _.clone to avoid using spread opearator but it doesn't work
var r = _.values(_.reduce(test,function (acc, e) {
acc[e.name] = {...(acc[e.name] || {}), ...e}; // this line is still in ES6
return acc;
},{}));