[1] const arr = [7, 8, 9];
const obj = {
a: 4,
b: 5,
c: 6
};
[2] for (let v in arr){
console.log(v);
}
// 0, 1, 2
[3 ]for (let v in obj){
console.log(v);
}
// a, b, c
[4] arr.child = 'child';
[5] arr.__proto__.getChild = function () {
return this.child;
};
[6] Array.prototype.parent = 'parent';
[7] for (let v in arr){
console.log(v);
}
// 0, 1, 2, child, getChild, parent
[8]for (let v of arr){
console.log(v);
}
// 7, 8, 9
[9] for (let v of arr.values()){
console.log(v);
}
// 7, 8, 9
[10] for (let v of obj){
console.log(v);
}
// 报错
[11] typeof arr.keys(); // 'object'
arr.keys() instanceof
(for in)遍历键名和 (for of)遍历键值,这种说法严谨吗?
![](https://img-home.csdnimg.cn/images/20240711042549.png)