Answers for "Merger Douplicate array"

0

Merger Douplicate array

var array = [{name:"foo1",value:"val1"},{name:"foo1",value:["val2","val3"]},{name:"foo2",value:"val4"}];

function mergeNames (arr) {
    return _.chain(arr).groupBy('name').mapValues(function (v) {
        return _.chain(v).pluck('value').flattenDeep();
    }).value();
}

console.log(mergeNames(array));
Posted by: Guest on May-06-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language