let arr = [1, 6, 5, 8, 9, '12']
let obj = {
double(n) {
return n % 2 === 0 ? n : '奇数'
}
}
console.log(Array.from(arr, function (n) {
return n % 2 === 0 ? n : '奇数'
}))
console.log(arr.includes(2))// includes返回布尔值
let newArr = arr.filter((item) => {
return item % 2 !== 0
})
console.log(newArr, arr)
// map在进行逻辑运算时会将返回的布尔值传递给新数组,
// 而filter这是过滤出符合该逻辑的数组元素将其返回给新数组
let newArr2 = arr.map((item) => {
return item % 2
})
console.log(newArr2, arr)
arr.forEach((item, index) => {
console.log(item,'=====', index)
})
console