【问题标题】:For Loop alternative with Lodash ( React Native )使用 Lodash 的 For Loop 替代方案(React Native)
【发布时间】:2020-11-10 20:14:31
【问题描述】:

我试图迭代一个数组并访问描述

数组

我正在像这样通过常规 for 循环进行迭代

 for (var index = 0; index <components.length; index++) {
    const msgs  = components[index].messages;
    for(var value = 0; value < msgs.length; value ++ ){
      console.log(msgs[value].description);
    }
  }

请告诉我如何通过在 react native 中使用 loadash 方法来简化它。

【问题讨论】:

    标签: arrays react-native sorting lodash


    【解决方案1】:

    这里使用的是lodash

    import {forEach} from 'lodash';
    
    
    forEach(components,(component,index)=>{
      const msgs  = component.messages;
      forEach(msgs,(msg,value)=>{
        console.log(msg.description);
      });
    });
    

    【讨论】:

      猜你喜欢
      • 2011-12-04
      • 2018-10-05
      • 1970-01-01
      • 1970-01-01
      • 2020-09-29
      • 1970-01-01
      • 1970-01-01
      • 2019-09-24
      • 1970-01-01
      相关资源
      最近更新 更多