我有一个奇怪的问题。我正在尝试使用 Javascript 从多维数组中获取一些值,它给了我一些奇怪的输出。
这是我的代码:
foo = [['3','4'],['5','6']];
for (bar in foo) {
baz = bar[0];
alert(baz);
qux = bar[1];
alert(qux);
}
这是上面的输出:
// These are all alerts, by the way
0,undefined,1,undefined,$,f,$,c,e,a,c,l,c,l,i,i,n,a,s,l,i,c,o,a,p,g,e,g,e,i,n,c,o,e,r,e,m,f,l,p,i,h,e,r,g
有人可以告诉我发生了什么吗?
这是问题的 jsFiddle:http: //jsfiddle.net/Jey6w/
编辑:
这是另一个 jsFiddle,还有一层“Inception”:http: //jsfiddle.net/8vyGq/
输出:
// Again, these are all alerts, and * signifies undefined
0**1**$ff$ceaacllcllinnassliicooappgeegeeinncooerremmfllpiiheergg