关于some和every它们之间不得不说的三十二件事

some

let a = [1,2,3,5,7].some(isBiggerThen10)   //false
let a = [1,2,3,5,7,10].some(isBiggerThen10) //true

对于 typed array 中的每个元素,some方法执行一次 callback,直到找到一个callback 返回 true 的元素. 如果一个元素被找到, some 立即返回 true. 否则, some 返回 false.

callback 期望3个参数: 元素的值, 元素的索引, 和被遍历的数组对象.

如果 some 提供 thisArg, 那么thisArg会作为 callback 调用时的this值. 否则, callback 调用时的 this 是 undefined.  callback 最终可观测的this 是根据  确定函数this的通常规则 所确定的.

some 被调用不会改变 typed array .

 

有一说一  如果有一个满足 那么some就会返回true   类似什么呢 类似  true || false  等于 true

 

const isBelowThreshold = (currentValue) => currentValue < 40;

const array1 = [1, 30, 39, 29, 10, 13];

console.log(array1.every(isBelowThreshold));
// expected output: true

要全部为true才为true    true && true

你可能感兴趣的:(js)