【问题标题】:How to return numbers from foreach in the intervals? [duplicate]如何在间隔中从foreach返回数字? [复制]
【发布时间】:2021-02-07 23:12:21
【问题描述】:

如何从foreach函数中按间隔返回数字?

我必须从我的foreach函数号间隔返回,所以例如我需要返回3,7,11,15,19,23,27,31 etc.

data.foreach(async (e, index) => {
    await this.getNumberInIntervals(e.id, index+4); // in this parameter I must be provide a numbers with interval by 4
})

谁能告诉我该怎么做?

这是一个不同的问题:Is there a difference between foreach and map?

【问题讨论】:

  • data 数组看起来如何?请提供准确的意见和期望

标签: javascript node.js typescript


【解决方案1】:
data.foreach(async (e, index) => {
    await this.getNumberInIntervals(index * 4 + 3);
})

【讨论】:

    猜你喜欢
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-08
    • 1970-01-01
    相关资源
    最近更新 更多