一、對於數組
var arr=['姚明','易建聯','張繼科'];
$.each(arr,function(index,value){
document.write(index+"="+value+"</br>");
});
for(var i in arr){
document.write(i+"</br>"); //獲得數組下標
document.write(arr[i]+"</br>");
}
二、對於對象
var object={name:"姚明",sex:'man'};
var o2={name="姚明",sex='man'};這么定義對象是錯誤的
$.each(o,function(key,value){
document.write(key+"="+value+"</br>");
});
for(var i in o){
document.write(i+"</br>"); // 獲得鍵值對的鍵key
document.write(o[i]+"</br>");
}
注:for()遍歷對象或者數組其格式一樣 document.write(arr[i]+"</br>"); document.write(o[i]+"</br>");