简体   繁体   English

按对象从对象数组中获取属性

[英]Get properties from array of objects group by objects

Good day, I have an array artists[] of Proxy-objects.美好的一天,我有一个代理对象数组artists[] Proxy by themself also are arrays of objects (as I understood).代理本身也是对象的 arrays (据我所知)。 Each of inner objects has property "artistName" (photo).每个内部对象都有属性"artistName" (照片)。 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.因此,我们得到按代理对象分组的艺术家姓名的 arrays。 Please, help!请帮忙!

There are two levels of arrays, so you'll need two loops (or map functions). arrays 有两个级别,因此您需要两个循环(或 map 函数)。 Give this a try试试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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