zoukankan      html  css  js  c++  java
  • JS中every()和some()的用法

    引自:https://www.cnblogs.com/yourstars/p/7822858.html

    every()与some()方法都是JS中数组的迭代方法。

    every()是对数组中每一项运行给定函数,如果该函数对每一返回true,则返回true。

    some()是对数组中每一项运行给定函数,如果该函数对任一返回true,则返回true。

    var arr = [ 1, 2, 3, 4, 5, 6 ]; 
     
    console.log( arr.some( function( item, index, array ){ 
        console.log( 'item=' + item + ',index='+index+',array='+array ); 
        return item > 3; 
    })); 
     
    console.log( arr.every( function( item, index, array ){ 
        console.log( 'item=' + item + ',index='+index+',array='+array ); 
        return item > 3; 
    }));
    

      

  • 相关阅读:
    正则表达式
    Ajax跨域问题---jsonp
    Ajax
    字符串总结
    js 字符串加密
    jsDate()
    HDU 5430 Reflect
    HDU 5429 Geometric Progression
    HDU 5428 The Factor
    POJ 2485 Highways
  • 原文地址:https://www.cnblogs.com/linwenbin/p/14034364.html
Copyright © 2011-2022 走看看