Maison  >  Questions et réponses  >  le corps du texte

对象属性的循环输出

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

哈哈哈哈哈哈2828 Il y a quelques jours1278

répondre à tous(2)je répondrai

  • 数据分析师

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

    Sortie en boucle des attributs d'objet-Q&A sur le site Web chinois PHP-Sortie en boucle des attributs d'objet-Q&A sur le site Web chinois PHP

    Jetez un œil et apprenez.

    répondre
    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即可。


    répondre
    0
  • 哈哈哈

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

    哈哈哈 · 2017-01-23 11:47:33
  • Annulerrépondre