数组合并concat,数组切片slice,event,循环遍历:map,forEach,筛选过滤:filter,查找:find,findIndex,reduce(),

本文介绍了JavaScript中处理数组的各种方法,包括数组合并、使用slice进行切片、every和some的判断、map和forEach的循环遍历、filter的筛选过滤、find和findIndex的查找以及reduce的综合应用。通过示例详细解释了reduce计算元素出现次数、转换多维数组为一维等操作。
摘要由CSDN通过智能技术生成

数组合并

let arr = [1, 2, 3, 4, 5, 6, 7];
const result = arr.concat([4, 5, 6], 7, 8);
console.log(result);

数组剪切:slice(index1,index2)

取数组下标[index1,index2),index1的下标取,index2小标对应的数据不取

    let arr = [1, 2, 3, 4, 5, 6, 7];
  let result = arr.slice(1, 5);//[2,3,4,5]
        console.log(result);

数组判断:every,some

every:这是判断数据是否含有某个数据,只要有一个不成立就返回:false,要全部都符合才会返回true

 const arr = [1,2,3,4,5,1024];
  const result = arr.every(item => {
            return item >1;
    });
  console.log(result); //false

some:只要找到一个符合条件的,就回来报告true 所以并不会全部遍历,不做多余的活(性能优良)

  const arr = [1,2,3024,4,5,1024];
    const result = arr.some(item => {
            return item > 2000;
        });
  console.log(result);
  },

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值