0

I have an array like this:-

[
    {"brand":"cadbury","category":"silk"},
    {"brand":"biba","category":"tops"},
    {"brand":"cadbury","category":"fruitnut"}
]

And I want to convert it to below format, tried many ways to do but not succedded:-

[
    {"brand":"cadbury","category":[{"name":"silk"},{"name":"fruitnut"}]},
    {"brand":"biba","category": [{"name":"tops"}] }
]

Basically after loop I want to combine all brands together.

BeingExpert
  • 523
  • 1
  • 5
  • 16
  • 1
    Please [edit] the question and add your attempts to solve the problem. – Tushar Jan 03 '17 at 03:33
  • 1
    What you are trying to do is usually called "grouping". It is often implemented by utilities such as those in lodash called `_.groupBy`. Search for `grouping javascript array` and you will find lots of references. –  Jan 03 '17 at 04:37

0 Answers0