曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 2397|回复: 0
打印 上一主题 下一主题

使用 for ... in 循环遍历数组

[复制链接]

4917

主题

5879

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34382
跳转到指定楼层
楼主
发表于 2011-12-14 13:12:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
可以用 for ... in 循环遍历数组中的每个元素,测试代码如下:
[code=javascript]<script type="text/javascript">
var WebSite = new Array();

WebSite["first"] = "www";
WebSite["second"] = "sina";
WebSite["third"] = "com";
WebSite["fourth"] = "cn";

var indexKey;

for (indexKey in WebSite) {
    document.write( "indexKey is " + indexKey + "<br>" );
    document.write( "item value is " + WebSite[indexKey] + "<br><br>" );
    }
</script>[/mw_shl_code]
运行输出:
indexKey is first
item value is www

indexKey is second
item value is sina

indexKey is third
item value is com

indexKey is fourth
item value is cn
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2024-5-17 04:22 , Processed in 0.061913 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表