Skip to content
Advertisement

How to group a column into comma-separated string based on multiple common key value pair?

This is my updated question. I have an array of objects like below:

JavaScript

I have to make a comma-seperated diameter based on the common manufacturer, colour & design.

My final output should be like this:

JavaScript

What I have tried so far is:

JavaScript

Here, what I get is diameter: “17, 17” instead of “17, 18”

Can anybody help me what mistake I have done?

Advertisement

Answer

You could loop through the array and set the manufacturer prop as the key of a new array:

https://paiza.io/projects/_ZzfxgMJjKIJIZAGSILmQA

JavaScript

Result:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement