1.遍历数组下标
for(let i=0;i<=arr.length;i++){
console.log(i);
}
for(let i in arr){
console.log(i);
}
for(let i of arr.keys()){
console.log(i);
}
2.遍历数组值
for(let i=0;i<=arr.length;i++){
console.log(arr[i]);
}
for(let i in arr){
console.log(arr[i]);
}
for(let m of arr){
console.log(m);
}
for(let m of arr.values()){
console.log(m);
}
3.遍历下标与值
for(let i=0;i<=arr.length;i++){
console.log(i+':'+arr[i]);
}
for(let i in arr){
console.log(i+':'+arr[i]);
}
for(let [p,q] of arr.entries()){
console.log(p+':'+q);
}
4.forEach()用法:仅用于遍历纯数组,参数为回调函数
arr.forEach(function(val,key){
console.log(key,val);
});