【问题标题】:Getting object array list from global Array with TypeScript使用 TypeScript 从全局数组中获取对象数组列表
【发布时间】:2021-06-29 15:27:48
【问题描述】:

给定一个包含以下内容的全局数组:

{
  id: 1,
  name: test,
  age: 23,
  toys: [
    { id: 2, label: mouse },
    { id: 1, label: house },
    { id: 4, label: car }
  ]
}

我想使用 ES6 TypeScript 仅提取给定孩子 id 的玩具数组

我试过了:

this.toys = this.kids.find(kid => kid.id === KidId);

谢谢。

【问题讨论】:

标签: javascript typescript ecmascript-6


【解决方案1】:

您只需拨打.toys:

this.toys = this.kids.find(kid => kid.id === KidId).toys;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-03
    • 2023-03-10
    • 2022-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多