Home > Enterprise >  Get properties from array of objects group by objects
Get properties from array of objects group by objects

Time:08-25

Good day, I have an array artists[] of Proxy-objects. Proxy by themself also are arrays of objects (as I understood). Each of inner objects has property "artistName" (photo). Meanwhile third Proxy has two.

enter image description here

I need to get smth like this:

[
  ["Queen"],
  ["Pink Floyd"],
  ["Elvis Presley", "Pink Floyd"],
]

So, as result we get arrays of artist's names grouped by Proxy objects. Please, help!

CodePudding user response:

There are two levels of arrays, so you'll need two loops (or map functions). Give this a try

const names = artists.map(grp => grp.map(band => band.artistName))
  • Related