📌  相关文章
📜  合并重复数组 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:29.747000             🧑  作者: Mango

代码示例1
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));