Home  >  Q&A  >  body text

对象属性的循环输出

var obj={x1:1,X2:2,X3:3};
var i= 1,n=3;
for(;i<=n;i++){
 document.write(obj['x'+i]+"<br>");
}
这里显示的结果为什么是:1,undefined,undefined

哈哈哈哈哈哈2827 days ago1273

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-09-30 23:56:29

    Loop output of object attributes-PHP Chinese website Q&A-Loop output of object attributes-PHP Chinese website Q&A

    Take a look around and learn.

    reply
    0
  • 怪我咯

    怪我咯2017-01-23 11:47:14

    var obj={x1:1,X2:2,X3:3};
    var i= 1,n=3;
    for(;i<=n;i++){
     document.write(obj['x'+i]+"<br>");
    }

    大小写问题 改成对应的小写x即可。


    reply
    0
  • 哈哈哈

    谢谢,居然没有注意这个问题

    哈哈哈 · 2017-01-23 11:47:33
  • Cancelreply