📜  for...of 和 for...in 语句之间的区别 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:49.145000             🧑  作者: Mango

代码示例1
const arr = [3, 5, 7];
arr.foo = 'hello';

for (let i in arr) {
   console.log(i); // logs "0", "1", "2", "foo"
}

for (let i of arr) {
   console.log(i); // logs 3, 5, 7
}