【问题标题】:Typescript return an array with manipulation on the objects打字稿返回一个对对象进行操作的数组
【发布时间】:2017-07-24 06:42:58
【问题描述】:

我的问题看起来很简单,但是我没有找到简单的方法。

在 Typescript 中,我想返回一个对内部每个对象进行操作的数组。

例如:

foo = [{code: 1, desc:"a"},
       {code: 2, desc:"b"},
       {code: 3, desc:"c"}];

get Foo() {
   return this.foo.forEach((item) => {
       return {code:item.code + 1, desc: item.desc};
   });
}

这个 getter 返回 undefined。

正确的做法是什么?

【问题讨论】:

标签: javascript typescript


【解决方案1】:

The forEach method 不返回任何内容,或者undefined

你可能想要the map method

【讨论】:

    猜你喜欢
    • 2018-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-25
    • 1970-01-01
    • 2021-05-24
    • 1970-01-01
    • 2019-02-13
    相关资源
    最近更新 更多