一 获取对象属性
var obj = {};
obj.name = 'xiaoming';
obj.['age'] = 26;
点 是取自身的属性 [ ] 可以是变量
例: var obj1 = {};
obj1.name = "n1";
var nameA = 'name';
console.log(obj1[nameA]); // ==> n1
console.log(obj1['nameA']); // ==> undefind
二 对象属性操作
删除属性: delete obj.name
检查属性:
console.log('name' in obj) ==> true;
console.log('name1' in obj) ==> false;
console.log(obj.hasOwnProperty("name"));
console.log(o.address !== 'undefind');
枚举属性
var obj4 = {x:1,y:2,z:3}
for (a in obj4) {console.log(a)}; // ==> x y z a其实为key
for (a in obj4) {console.log(obj4[a])}; // ==> 1 2 3
var arr = [{x:1},{y:2},{z:3}];
for (a in arr) {console.log(a)}; // ==> 0 1 2 索引
for(var i=0; i < 10; i++){};
$.each(arr, function(index, item)) { }
for循环是同步的 (非得拿到了在去循环) $.each是异步的