```
//forEah 不支持return
arr.forEach((item)=>{ // 聲明式 (不關心如何實現)
// console.log(item);
})
json.forEach(function(v,k){ //不能遍歷對象json,只支持數組和類數組
console.log(k,v); //報錯
})
```
```
//in 支持對象和數組
for(let key in arr){ //key會把數字的索引變成字符串作為鍵名
// console.log(typeof key);
// console.log(key); //能打印出數組的自定義屬性
}
//of 僅支持數組
for(let val of arr){ //支持return 并且是值of數組 不能遍歷對象
// console.log(val);
}
//讓of支持對象
for(let val of Object.keys(obj)){
console.log(obj[val]);
}
```
## for中let和var的區別
