for in是ES5标准,遍历key,遍历的是数组的索引(即键名);
for of是ES6标准,遍历value,遍历的是数组元素值;
Object.prototype.objCustom = function () {};
Array.prototype.arrCustom = function () {};
let iterable = [3, 5, 7];
iterable.foo = "hello";
for (let i in iterable) {
console.log(i);
}
// 0, 1, 2, "foo", "arrCustom", "objCustom"
for (let i of iterable) {
console.log(i);
}
// 3, 5, 7