zoukankan      html  css  js  c++  java
  • 数组的5个迭代方法

    数组的5个迭代方法
    every()对数组中的每一项运行给定的函数,如果该函数对每一项都返回true,则返回true。
    some()对数组中的每一项运行给定的函数,如果该函数对任一项返回true,则返回true。
    filter()对数组中的每一项运行给定的函数,返回该函数会返回true的项组成的数组。
    map()对数组中的每一项运行给定的函数,返回每次函数调用的结果组成的数组。
    forEach()对数组中的每一项运行给定的函数,这个方法没有返回值。

    标注:参数是个函数。

    var arr=[2,3,2,4,22,3,1,34,32,13,0];
    console.log(arr.every(function(item,index,array){
    return item>3;
    }))//false
    console.log(arr.some(function(item,index,array){
    // console.log(array);
    return item>3;
    }))//true
    console.log(arr.filter(function(item,index,array){
    // console.log(array);
    return item>22;
    }))//[34, 32]
    console.log(arr.map(function(item,index,array){
    return item+=1;
    }))//[3, 4, 3, 5, 23, 4, 2, 35, 33, 14, 1]
    arr.forEach(function(item,index,array){
    // console.log(array);
    if(item==3){
    console.log(index);
    }
    })

  • 相关阅读:
    分布式事务的MQ实现
    zipkin 介绍入门
    线程5问?
    微服务分布式系统架构,转载,备份
    微服务,分布式架构
    史上最全 40 道 Dubbo 面试题及答案,看完碾压面试官!
    Tomcat优化
    windows 下安装kafka
    经典台词
    分布式锁3种实现
  • 原文地址:https://www.cnblogs.com/studyh5/p/9700399.html
Copyright © 2011-2022 走看看