【问题标题】:How to limit a .map() [duplicate]如何限制 .map() [重复]
【发布时间】:2020-07-05 12:08:17
【问题描述】:

如何限制此 MAP,以便我只搜索前 3 个项目,干净利落?

const Xx = actives.map(it => ({
    x: it.ticker,
    y: it.percent,
    label: it.percentual,
}));

【问题讨论】:

    标签: javascript


    【解决方案1】:
    const arr = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
    
    const Xx = arr.slice(0, 3).map(el => ({
      x: el.id,
    }));
    
    console.log(Xx)
    

    【讨论】:

      猜你喜欢
      • 2019-10-15
      • 1970-01-01
      • 2012-08-06
      • 2017-12-10
      • 2013-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      相关资源
      最近更新 更多