for-in
for-in循环实际是为循环”enumerable“对象而设计的:
var obj = {a:1, b:2, c:3};
for (var prop in obj) {
console.log("obj." + prop + " = " + obj[prop]);
}
// 输出:
// "obj.a = 1"
// "obj.b = 2"
// "obj.c = 3"
for-of
for of循环比传统的for循环简洁,同时弥补了forEach和for-in循环的短板
let iterable = [10, 20, 30]; for (let value of iterable) { console.log(value); } // 10 // 20 // 30
forEach
-
myArray.forEach(function (value) {
-
console.log(value);
-