JavaScript 几种for循环的比较。

let array = [1, 2, 3, 4];
array.dec = ‘numbers’;

//forEach 方法不允许 breakbreak 提出循环 forEach 方法循环出来没有属性
// array.forEach((value) => console.log(value));

//for in 循环出来的键值对的的 键。
//forEach 和 for of 循环出来的是值。 forEach 不能被打断,for of 可以被打断
for (let n of array) {
if (n > 3) break;
console.log(n);
// console.log(array[n])
}

猜你喜欢

转载自blog.csdn.net/yufanhui/article/details/84677225