js数组常用方法

1.find

find() 方法返回数组中满足提供的测试函数的第一个元素的值。否则返回 undefined

const array1 = [5, 12, 8, 130, 44];

const found = array1.find(it=> it> 10);

console.log(found);//  12

2.some

some() 方法测试数组中是不是至少有 1 个元素通过了被提供的函数测试,剩余的元素不会再执行检测,它返回的是一个 Boolean 类型的值。

const array = [1, 2, 3, 4, 5];

const even = (it) => it% 2 === 0;

console.log(array.some(even));//true

3.every

every() 方法测试一个数组内的所有元素是否都能通过某个指定函数的测试。它返回的是一个 Boolean 类型的值。
tips:若收到一个空数组,此方法在任何情况下都会返回 true。

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

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

console.log(array1.every(isBelowThreshold));// true

你可能感兴趣的:(JavaScript,项目总结,ES6,javascript,前端,vue.js)