arrays - 使用 Lodash 的 For Loop 替代方案(React Native)
问题描述
我试图迭代一个数组并访问描述
我正在像这样通过常规 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 方法来简化它。
解决方案
这里使用的是 lodash
import {forEach} from 'lodash';
forEach(components,(component,index)=>{
const msgs = component.messages;
forEach(msgs,(msg,value)=>{
console.log(msg.description);
});
});
推荐阅读
- javascript - Chrome 图标看起来很苍白
- mysql - 使用 MySQL 连接器 (.NET) 导致锁定的并发 MySQL 事务
- java - 创建一个类。添加以下方法:min、max、isEven、square。在 main 方法中,调用那些方法
- python-3.x - ATBS Regex Search Project-如何解决本地范围错误?
- java - 无法将 Java 项目中的类文件导入同一项目中的另一个类文件
- c++ - 带有通配符和标头的不同文件夹中的 Makefile 对象(模块化编译)?
- wagtail - 如何 ajaxify Wagtail-CMS 页面的操作?
- javascript - 隐藏输入/选择时,表单字段标签不会隐藏
- django - 如何在 Django 中正确保存 FileField 的实例
- aws-codecommit - 在 AWS CodeCommit 中获取树