Skip to content
Advertisement

Get properties from array of objects group by objects

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!

Advertisement

Answer

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))
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement