<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>四种js遍历数组方法</title>
</head>
<body>
js遍历数组
<script>
var a=new array( 'a '=> 'aa ', 'b '=> 'bb ');
for(i in a)
{
alert(i);
}
</script>
遍历数组二
var array32=new array();
array32 =[
['show',10,'plan3_2_1'],['show',10,'plan3_2_2'],['show',120,'plan3_2_3'],['show',120,'plan3_2_4'],
['show',30,'plan3_2_5'],['show',30,'plan3_2_6'],['show',5,'plan3_2_7'],['show',10,'plan3_2_8'],
['show',10,'plan3_2_9'],['show',2,'plan3_2_10'],['show',2,'plan3_2_11'],['show',1,'plan3_2_12'],
['show',1,'plan3_2_13'],['show',1,'plan3_2_14'],['show',2,'plan3_2_15'],['show',2,'plan3_2_16'],
['0',0,'plan3_2_17']
];
for(var i=0;i<array32.length;i++){
var array32_tr=new array();
array32_tr=array32[i];
for(var j=0;j<array32_tr.length;j++){
//设置select的选中状态
var select = document.getelementbyid(array32_tr[2]+"_select");
for(var k=0;k<select.options.length;k++){
if(select.options[k].value==array32_tr[0]){//数组的第一项都是选中状态
select.options[k].selected=true;
}
if(arraytr[0]=='show'){
document.getelementbyid(array32_tr[2]+"_input").value=array32_tr[1];//设置input属性的值
document.getelementbyid(array32_tr[2]+"_td").style.display='';//显示文本框
}
}
}
}
第三种遍历数组方法
遍历数组
var dd = {
'a' : '111111',
'b' : '222222',
'c' : '333333'
}
dd['d'] = ['444444','55555555'];
// 遍历数组
function scan_array(arr) {
for(var key in arr) { // 这个是关键
if(typeof(arr[key]) == 'array' || typeof(arr[key]) == 'object') {// 递归调用
scan_array(arr[key]);
} else {
document.write(key + ' = ' + arr[key] + '<br>');
}
}
}
</body>
</html>