程序笔记   发布时间:2022-07-12  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ES6的几个数组大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
ES6 some和forEach对比

some:当找到需要的值时,会停止寻找。

forEach:找到需要的值后,继续向后寻找。

1.some

var arr=["xx","jj","xxjj"];arr.some((item,indeX)=>{if(item === "xx"){console.log(indeX)//再找到对应选项后,通过return true来终止语句执行。return true}})

2.forEach

var arr=["xx","jj","xxjj"];arr.forEach((item,indeX)=>{if(item==="xx"){console.log(indeX)}})ES6 every

当查询的每一项都为符合条件时返回true

const arr = [{id:1,name:'西瓜',status:truE},{id:2,name:'榴莲',status:truE},{id:3,name:'草莓',status:truE},]const result = arr.every(item=>item.status  == "true")console.log(result)

ES6 reduce

forEach写法

const arr = [{id:1,name:'西瓜',status:truE},{id:2,name:'榴莲',status:truE},{id:3,name:'草莓',status:truE},]let amt = 0;arr.filter(item=> item.statE).forEach(item=>{    amt+=item.price*item.count})

reduce写法

const arr = [{id:1,name:'西瓜',status:truE},{id:2,name:'榴莲',status:truE},{id:3,name:'草莓',status:truE},]const result = arr.filter(item=>item.statE).reduce((amt,item)=>{return amt += item.price * item.count})

 

大佬总结

以上是大佬教程为你收集整理的ES6的几个数组全部内容,希望文章能够帮你解决ES6的几个数组所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。