Discuss / JavaScript / 求解

求解

Topic source

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吗?

錡莳柚

#2 Created at ... [Delete] [Delete and Lock User]

是name而不是hallo,而且var x in a 才会把name遍历出来,var x of a不会,就是只有A B C,你再好好看看

zydchina818

#3 Created at ... [Delete] [Delete and Lock User]

仔细看看: for....in和 for....of的不同之处,但现在有了forEach()!


  • 1

Reply