var a = ['A', 'B', 'C'];
a.name = 'Hello';
for (var x of a) {
console.log(x); // 'A', 'B', 'C'
}
这个为什么输出ABC而没有Hello,不是A,B,C,Hello吗?
是name而不是hallo,而且var x in a 才会把name遍历出来,var x of a不会,就是只有A B C,你再好好看看
仔细看看: for....in和 for....of的不同之处,但现在有了forEach()!
Sign in to make a reply
奶黄包丸子
var a = ['A', 'B', 'C'];
a.name = 'Hello';
for (var x of a) {
console.log(x); // 'A', 'B', 'C'
}
这个为什么输出ABC而没有Hello,不是A,B,C,Hello吗?