Javascript数组——some()、every()、forEach()遍历区别
2021-06-09 03:04
标签:ret reac code strong 数组 退出 color turn console some() every() forEach() Javascript数组——some()、every()、forEach()遍历区别 标签:ret reac code strong 数组 退出 color turn console 原文地址:https://www.cnblogs.com/zuiyue_jing/p/14498826.html
var list=[1,2,3,4,5,6]
var sum = 0;
list.some(obj->{
sum = sum + obj;
if(obj === 5)
return true
})
console.log(sum);
//sum == 10
var list=[1,2,3,4,5,6]
var sum = 0;
list.euery(obj->{
sum = sum + obj;
if(obj === 5)
return false
})
console.log(sum);
//sum == 10
var list=[1,2,3,4,5,6]
var sum = 0;
list.some(obj->{
sum = sum + obj;
if(obj === 3)
return true
if(obj === 4)
return false
if(obj === 5)
return
})
console.log(sum);
//sum == 21
文章标题:Javascript数组——some()、every()、forEach()遍历区别
文章链接:http://soscw.com/index.php/essay/92499.html