【问题标题】:Collect all property names of filtered objects based on criteria根据条件收集过滤对象的所有属性名称
【发布时间】:2019-07-27 11:10:27
【问题描述】:

我有一个数组如下

[
  {
    "id": 82,
    "name": "fromcreate_date",
    "displayName": "From Create Date",
    "uiControl": "DATERANGE",
  },
  {
    "id": 82,
    "name": "tocreate_date",
    "displayName": "To Create Date",
    "uiControl": "DATERANGE",
  },
  {
    "id": 83,
    "name": "p_is_ut",
    "displayName": "Is UT",
    "uiControl": "HIDDEN",
   }
]

我想根据uiControl === "DATERANGE" 过滤这个数组,并只获取数组中过滤对象的name 属性,如下所示。

outputArray = ["fromcreate_date", "tocreate_date"]

【问题讨论】:

  • 试试这个: const result = this.data.filter(x => x.uiControl === 'DATERANGE').map(x => x.name);
  • 谢谢。那行得通。我可以接受您选择将其发布为答案的答案。

标签: arrays angular typescript object filter


【解决方案1】:

试试这个简单的衬里:

const outputArray = this.data.filter(x => x.uiControl === 'DATERANGE').map(x => x.name);

【讨论】:

    猜你喜欢
    • 2018-05-27
    • 2010-09-25
    • 2018-09-07
    • 2018-04-07
    • 2015-05-30
    • 1970-01-01
    • 2016-08-19
    • 2018-12-25
    • 2023-03-08
    相关资源
    最近更新 更多