//最簡單的對象
var o = {
'name':"哈哈",
'age' : 30,
'level':"2b",
'sex' : '男'
};
$.each(o, function(key, value){
console.log(key, value);
});
//最基本的數組
var a = [3,4,5,6,7];
$.each(a, function(key, value){
console.log(key, value);
});
//又像數組,又像對象(暈暈的,$.each不循環)
var arr = [];
arr['name'] = "helios";
arr['version'] = 'trunk';
console.log(arr, typeof arr);
console.dir(arr);
$.each(arr, function(key, item){
console.log(key, item, item[key]);
});
console.log( Object.prototype.toString.call(arr) );
console.log( arr.constructor , arr.constructor === Array);
console.log(arr && typeof(arr) === "object" && arr.constructor === Array);
var a1 = [], b1 = {};
console.log(typeof a1, typeof b1);
//JSON數據
var s = [{
'name':"哈哈",
'age' : 30,
'level':"2b",
'sex' : '男'
},{'name':"嘿嘿",
'age' : 30,
'level':"3b",
'sex' : '男'
}];
$.each(s, function(index, item){
console.log(index, item, item.name);
});