关于数组中forEach() 、map()、filter()、reduce()、some()、every()的总结

let arr = [1, 2, 3, 4, 5]

//  forEach遍历数组
arr.forEach((item,index,self)=>{
console.log(item*10)
}) // map遍历数组,返回一个新数组 (用作统一修改数组项)
let r1 = arr.map((item, index, self) => {
return item * 10
}) console.log(r1) // filter过滤出满足条件的值,返回一个新的数组 (用作数组过滤)
let r2 = arr.filter((item, index, self) => {
return item > 2
})
console.log(r2) // reduce前一项一直作用于后一项上(可以用作数组求和或求阶乘)
let r3 = arr.reduce((result, item, index, self) => {
return result + item
})
console.log(r3) // someh找到满足条件的第一个就停止(检测数组中的是否存在满足条件的项目),并返回true,如果都不满足,返回false
let r4 = arr.some((item,index)=>{
return item//2 === 0,index
}) console.log(r4) // every 其中有一项不满足就返回false,否则返回true (检测数组中是否都满足条件 )
let r5 = arr.every((item,index)=>{
return item<5
})
console.log(r5)

ES6数组新增方法总结的更多相关文章

  1. es6 数组新增方法

    1.Array.from(): 这个函数的作用是将类似数组的对象转化为数组,比如DOM对象 let arrayLike = {      "0":"TangSir&quo ...

  2. JavaScript ES6 数组新方法 学习随笔

    JavaScript ES6 数组新方法 学习随笔 新建数组 var arr = [1, 2, 2, 3, 4] includes 方法 includes 查找数组有无该参数 有返回true var ...

  3. ES6 数组遍历方法的实战用法总结(forEach,every,some,map,filter,reduce,reduceRight,indexOf,lastIndexOf)

    目录 forEach every some map filter reduce && reduceRight indexOf lastIndexOf 前言 ES6原生语法中提供了非常多 ...

  4. es6数组的方法

    1.复习的函数 函数是由关键字function声明的,他是一个引用数据类型,是Function的实例,在调用的时候会开辟一个私有空间 2.函数的成员 arguments:null  (是实参构成的数组 ...

  5. ES6数组去重方法

    Set实例的方法分为两大类:操作方法(用于操作数据)和遍历方法(用于遍历成员),操作方法有:add(value).delete(value).has(value).clear():遍历方法有:keys ...

  6. ES6 数组的方法

     数组的类 数组的类是Array 数组的定义 var arr=[元素] var arr=new Array(3) 数字3,代表有三个元素或者三个空位 如果数组定义采用 new 实例,类中跟的是一个数字 ...

  7. ES6数组新增的几个方法

    关于数组中forEach() .map().filter().reduce().some().every()的总结 1.forEach() var arr = [1,2,3,4]; arr.forEa ...

  8. es6 数组扩展方法

    1.扩展运算符 含义: 扩展运算符,三个点(...),将一个数组转为用逗号分隔的参数顺序. 例如: console.log([1,2,3]); console.log(...[1,2,3]);   结 ...

  9. es6数组新方法

    (1)Array.from(aarr,fn,obj) function fn(dr, sd, d) { /*Array.from 类数组转化为数组*/ console.log(arguments) v ...

随机推荐

  1. c语言学习笔记 scanf和printf格式的问题

    int a =0; int b =0; scanf("%d %d",&,&b); 上面这种和下面这种哪种对? int a =0; int b =0; scanf(& ...

  2. 20、Basic Shell_for_while_grep_find

    转载:https://github.com/swcarpentry/DEPRECATED-boot-camps/blob/master/shell/shell_cheatsheet.md 1.For ...

  3. noi.ac day1t1 candy

    传送门 分析 我们知道如果设A,B分别为将两家店从大到小排序之后各自的前缀和,则 Ans=Max{Min{A[i],B[j]}-W*(i+j)}. 为了得到这个Ans我们可以枚举两个数的Min,然后剩 ...

  4. 51NOD1052 最大M字段和

    传送门 分析 一眼看去我们自然会想到dp[i][j][k]表示区间[i,j]中选k个子段的最大值.然后我们考虑降去一维.我们设dp[i][j]表示考虑了前i个数,在选了a[i]的情况下共有j个子段的最 ...

  5. 使用Spring加载properties配置文件.md

    背景 类似于datasource.properties之类的配置文件,最初通过Java的Properties类进行处理.这种方式有许多弊端,如每次都需要读取配置文件:若将Properties作为成员变 ...

  6. Java 接口实际应用代码

    package interfaceDemo; interface Equipment_specifications{ void DoWork(); } class MBorad{//主板 privat ...

  7. Sql Server 数据恢复-破解版

    首先,恭喜大家进了误删误改使得数据丢失的坑~~~~~ 不要担心,恢复就好了. 下载地址:https://pan.baidu.com/s/1a59U--Y6EmbPF2CFsxmo2Q 密码:jb14 ...

  8. Wannafly挑战赛28B(DP,思维,字符串)

    #include<bits/stdc++.h>using namespace std;int n;int nxt[3][100007];char buff[100007];const ch ...

  9. Pyinstaller打包matplotlib.pyplot画图时提示无法找到Qt插件的解决办法

    This application failed to start because it could not find or load the Qt platform plugin "wind ...

  10. MySQL数据库之插入显示图片

    图书馆系统项目需要用到好多图片,并且要求存入到数据库中,对这个特别感兴趣,于是上网查了资料,采用C#语言,进行了具体实现. 说明: 功能:往MySQL数据库插入并显示图片: 验证:执行插入功能后,我把 ...