javascript - 如何在javascript中摆脱数组中的数组
问题描述
const addressZip = person.get('addresses').filter((address) => address.get('legacy_id')).filter((newAddress) => (
getZIPErrors(newAddress.get('zip'))
))
执行此函数时,
[array(0)]
如果没有错误,它会以 . 的形式返回我[array(1)]
。
如果它没有错误[]
并且如果它有错误它应该像['invalid']
解决方案
您可以在 Array 构造函数中实现 concatAll 方法,然后使用它来展平您的结果:
Array.prototype.concatAll = function() {
return this.reduce((acc, curr) => acc = acc.concat(curr))
}
const addressZip = person
.get('addresses')
.filter(address => address.get('legacy_id'))
.filter(newAddress => getZIPErrors(newAddress.get('zip')))
.concatAll()
推荐阅读
- javascript - Javascript .scrollTop 在 iOS Safari 中不起作用
- python - 如何在python3的列表理解中使用下一个迭代器来获取没有任何前导零的列表
- c# - 在一台设备上使用代码并使用推送通知与其他设备显示“结果”
- xml - 如何遍历多个 xml 文件解析它们并发送到 REST API
- java - 自定义区域设置 - 英文显示 - FRENCH DateFormat
- excel - 为什么 isnumber 搜索不能正确处理给定的数据?
- javascript - Unicode 正则表达式:编译失败:字符类中的范围无序
- python-3.x - Python 矢量化与 Julia for 循环
- git - Azure 门户 - 无法为 Web 应用程序中的部署槽设置部署
- python-3.x - 如何使用 tensorflow keras 将深度重写为法线贴图代码以进行输入浴?