//使用for of
const arr = [1,1,2,3,4,5];
for(const i of arr){
console.log(i%2===0?'even':'odd');
}
//使用for循环
const arr = [1,1,2,3,4,5];
for(let i=0;i<arr.length;i++){
console.log(i%2===0?'even':'odd');
}
//使用forEach
` const arr = [1,1,2,3,4,5,2,23];
arr.forEach(i=>{
console.log(i%2===0?'even':'odd')
}
)
遍历数组的三种方法
最新推荐文章于 2024-06-18 09:23:47 发布