I have an array of objects I want to group/merge the objects which have similar branches and environments and concat their pools at the same time.
const data = [
{
branch: "master",
environment: "dev",
pool: "6g",
service: "amex",
},
{
branch: "master",
environment: "dev",
pool: "6g",
service: "amex",
},
{
branch: "feature/rest",
environment: "dev",
pool: "2g",
service: "amex",
},
{
branch: "master",
environment: "dev",
pool: "4g",
service: "amex",
},
{
branch: "hotfix/23",
environment: "test",
pool: "9g",
service: "amex",
},
{
branch: "hotfix/23",
environment: "test",
pool: "1g",
service: "amex",
},
];
I want the result in the below format removing duplicate objects as well I tried to reduce it but as array reduce returns a single object as a result and the other objects are being omitted from the response what data structure or way I can use to achieve the result?
const result = [
{
branch: "master",
environment: "dev",
pool: "6g, 4g",
service: "amex",
},
{
branch: "feature/rest",
environment: "dev",
pool: "2g",
service: "amex",
},
{
branch: "hotfix/23",
environment: "test",
pool: "9g,1g",
service: "amex",
},
];
Array.map()master, and then work with new created arrays