第一种方法 fliter
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var result = arr.filter(function (item) {
return item % 2 === 0
})
console.log(result);
// (5) [2, 4, 6, 8, 10]
ES6 的方法 findIndex
// 数组
var nums = [1, 3, 4, 6, 5, 7, 9];
// 查找成员
// var result = nums.indexOf(function() {
// console.log()
// })
// var result = nums.find(function(item, index, arr) {
// console.log(arguments, this);
// // 是偶数
// return item % 2 === 0
// })
var result = nums.findIndex(function(item, index, arr) {
console.log(arguments, this);
// 是偶数
return item % 2 === 0
})
console.log(result);