looking for some solutions? You are welcome.

SOLVED: How to Group by json array by two same key

Tamilselvan:

How to group by based on two json key which is f and b My json array

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    },

];

Expected Output

 var op=[
    {   s:'s',  f:1,  b:1,  q:5   },
    {   s:'s',  f:2,  b:1,  q:4   },
    {   s:'s',  f:1,  b:2,  q:4   },
    {   s:'s',  f:0,  b:1,  q:4   },
    {   s:'s',  f:1,  b:0,  q:4   },
    {   s:'s',  f:0,  b:0,  q:4   },

];



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent