数组遍历六种方法
1. some (ck) ----- 某个一个为true,则为true ,且找到为true ,退出循环
对数组中每个元素执行一次ck函数,知道某个元素返回true,则直接返回true。如果都返回false,则返回false
检查整个数组中是否有满足ck函数的元素。
![](https://upload-images.jianshu.io/upload_images/5221572-1240f86df8b45a33.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/788/format/webp)
result 当符合条件为true 退出循环
![](https://upload-images.jianshu.io/upload_images/5221572-65efca60a58df485.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/575/format/webp)
log 日志
没有满足函数条件时 返回false
![](https://upload-images.jianshu.io/upload_images/5221572-49b3c04125400d94.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/156/format/webp)
log 日志
2. every() -----某一个为false,则返回false
![](https://upload-images.jianshu.io/upload_images/5221572-0bd921c2cf6eb327.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/776/format/webp)
循环返回 返回false 时 退出 并终止循环
![](https://upload-images.jianshu.io/upload_images/5221572-5e4a9dac2b0a1e70.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/239/format/webp)
log日志
3. forEach () ---- 仅循环
![](https://upload-images.jianshu.io/upload_images/5221572-a8c784e9e2e3954b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/908/format/webp)
![](https://upload-images.jianshu.io/upload_images/5221572-cf4b12b662f33dac.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/665/format/webp)
log日志
![](https://upload-images.jianshu.io/upload_images/5221572-be34894b9ebb56b1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/432/format/webp)
全部为true 时返回 true
4. map() ---- 返回每个元素返回值的集合
![](https://upload-images.jianshu.io/upload_images/5221572-cdbfd62aa67c049e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/874/format/webp)
![](https://upload-images.jianshu.io/upload_images/5221572-039d3790bcb90f0a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/459/format/webp)
log日志
5. filter() ----得到返回值为true的元素的集合 (过滤器)
![](https://upload-images.jianshu.io/upload_images/5221572-abba460a7ffc920a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
![](https://upload-images.jianshu.io/upload_images/5221572-b0ea1bc00fdda635.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/314/format/webp)
log日志
没有符合条件时, 返回空数组
![](https://upload-images.jianshu.io/upload_images/5221572-1a405f4efd55d1bf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/198/format/webp)
log日志
6. reduce(ck,init ) -----依次执行ck(prv.next)
![](https://upload-images.jianshu.io/upload_images/5221572-c0b45cd780fe9321.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/820/format/webp)
![](https://upload-images.jianshu.io/upload_images/5221572-fa5c9fb420bf453a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/340/format/webp)
init 为初始值,不设置时默认为数组下标为0 元素
![](https://upload-images.jianshu.io/upload_images/5221572-a04809fc2bbb51e0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/924/format/webp)
![](https://upload-images.jianshu.io/upload_images/5221572-0a3a1cf39a840688.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/475/format/webp)