//every():如果该函数对“每一项”都返回true,则返回true, some()如果该函数对“任一项”返回true,则返回true。
var arrName = [ "zhaoqian", "sunli", "zhouwu", "zhengwang", "chengsi", "wuwei" ];
console.log( arrName.some( function( item, index, array ){
console.log( 'item=' + item + ',index='+index+',array='+array );
return item == "zhengwang";
}));
打印结果:
item=zhaoqian,index=0,array=zhaoqian,sunli,zhouwu,zhengwang,chengsi,wuwei
item=sunli,index=1,array=zhaoqian,sunli,zhouwu,zhengwang,chengsi,wuwei
item=zhouwu,index=2,array=zhaoqian,sunli,zhouwu,zhengwang,chengsi,wuwei
item=zhengwang,index=3,array=zhaoqian,sunli,zhouwu,zhengwang,chengsi,wuwei
true
console.log( arrName.every( function( item, index, array ){
console.log( 'item=' + item + ',index='+index+',array='+array );
return item == "zhengwang";
}));
打印结果:
item=zhaoqian,index=0,array=zhaoqian,sunli,zhouwu,zhengwang,chengsi,wuwei
false