JS遍歷打印、遍歷數組

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>');  
}  
}  

 

from:gaohui blog

You May Also Like