处理Array数组中的方法集合

// for循环
for(let i=0; i < arr.length; i++){
    // handel
}

// for...in:得到对像的key,数组、字符串的下标
for(index  in arr){
    // handel
}

// for...of:得到数组的值
// for...of循环(可循环Arrays(数组), Strings(字符串), Maps(映射), Sets(集合)等可迭代的数据结构等)
// 注意: for...of 不能遍历对象
for(let item of arr){
    // handel
}

// forEach():对数组的每个元素执行一次提供的函数,功能和for循环类似不过不能提前终止循环
arr.forEach((item,index,arr) => { // item为遍历的当前元素,index为当前索引,array为正在操作的数组
	// handel
},thisValue) // thisValue为执行回调时的this值

// map():通过指定函数处理数组的每个元素,并返回处理后的数组
arr.map((item,index,arr) => { // item为遍历的当前元素,index为当前索引,array为正在操作的数组
	// handel
},thisValue) // thisValue为执行回调时的this值

// some():用于检测数组中的元素是否满足指定条件(函数提供)
arr.some((item,index,arr) => { // item为遍历的当前元素,index为当前索引,array为正在操作的数组
	// handel
},thisValue) // thisValue为执行回调时的this值

// every():用于检测数组所有元素是否都符合指定条件(通过函数提供)
arr.every((item,index,arr) => { // item为遍历的当前元素,index为当前索引,array为正在操作的数组
	// handel
},thisValue) // thisValue为执行回调时的this值

// filter():创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素
arr.filter((item,index,arr) => { // item为遍历的当前元素,index为当前索引,array为正在操作的数组
	// handel
},thisValue) // thisValue为执行回调时的this值

// find():找到第一个符合条件元素,返回该元素,否则返回undefined
arr.find((item,index,arr) => { // item为遍历的当前元素,index为当前索引,array为正在操作的数组
	// handel
},thisValue) // thisValue为执行回调时的this值

// reduce():找到第一个符合条件元素,返回该元素,否则返回undefined
arr.reduce((total,item,index,arr) => { //total为初始值或者计算结束后的返回值,item为当前元素,index为当前元素的索引,array为当前元素所属的数组对象,
	// handel
},initialValue) // thisValue为传递给函数的初始值

// reverse():对数组进行反向排序
arr.reverse() 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值