[Solved] How to Group by json array by two same key [closed]


var json=[
    {   s:'s',  f:1,  b:1,  q:2   },
    {   s:'s',  f:1,  b:1,  q:3   },
    {   s:'s',  f:2,  b:1,  q:2   },
    {   s:'s',  f:2,  b:1,  q:2   },
    {   s:'s',  f:1,  b:2,  q:2   },
    {   s:'s',  f:1,  b:2,  q:2   },
    {   s:'s',  f:0,  b:1,  q:2   },
    {   s:'s',  f:0,  b:1,  q:2   },
    {   s:'s',  f:1,  b:0,  q:2   },
    {   s:'s',  f:1,  b:0,  q:2   },
    {   s:'s',  f:0,  b:0,  q:2   },
    {   s:'s',  f:0,  b:0,  q:2   },
];

var result = Object.values(json.reduce((list, cur) => {
    if(list[cur.f + ',' + cur.b])
        list[cur.f + ',' + cur.b].q += cur.q
    else
        list[cur.f + ',' + cur.b] = Object.assign({}, cur)
    return list
}, {}))
console.log(result)

2

solved How to Group by json array by two same key [closed]