find() 返回第一个符合条件的元素;
filter() 返回所有符合条件的元素组成的数组;
map() 遍历所有元素,判断每个元素是否符合条件,返回其对应的boolean组成的数组;
map((index)=>{ }) 也可以对所有元素进行处理。
var arr = [9, 4, 6, 12, 6, 1];
var newArrays1 = arr.find(index => index !== 9);
var newArrays2 = arr.filter(index => index <= 6);
var newArrays3 = arr.map(index => index === 6);
var newArrays4 = arr.map((index) => {
return index + 1
})
console.log(newArrays1); //4
console.log(newArrays2); //[4, 6, 6, 1]
console.log(newArrays3); //[false, false, true, false, true, false]
console.log(newArrays4); //[10, 5, 7, 13, 7, 2]