JavaScript之对象应用

<script>
    obj={"111":"one","222":"two","333":"three"};
    var i;
    for(i in obj)
    {
        console.log(i); 
        console.log(obj[i]);
    }
</script>

上面的代码运行后,在控制台显示:

111

one
222
two
333

three

即for循环中i每次取值为对象obj中的键(keys),而值是通过obj[i]来获取的.

posted @ 2020-01-05 09:44  Iceberg_710815  阅读(170)  评论(0编辑  收藏  举报