标签:ret reac code strong 数组 退出 color turn console
some()
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
every()
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
forEach()
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()遍历区别
标签:ret reac code strong 数组 退出 color turn console
原文地址:https://www.cnblogs.com/zuiyue_jing/p/14498826.html