简体   繁体   中英

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.

在此处输入图像描述

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!

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM