var obj = { 'a': { a: "222" }, 'b': 'Haidian' };
var arr = ["jack", "tom", "bob", "jerry"]
var string = "abcedfg"
console.log(Object.values(obj)); //[{"a": "222"},"Haidian"]
console.log(Object.keys(obj))//["a", "b"]
console.log(Object.values(obj).length);//2
console.log(Object.keys(obj).length);//2
console.log(Object.keys(arr));//["0", "1", "2", "3"]
console.log(Object.keys(string));//["0", "1", "2", "3", "4", "5", "6"]
let o = { a: 1 }
o.hasOwnProperty('a') //true
o.hasOwnProperty('b') //false 对象自身没有属性b
o.hasOwnProperty('toString'); //false 不能检测对象原型链上的属性
var buz = {
"a": {
fog: 'stack',
name: "2222"
},
"b": {
fog: 'stack',
name: "1111"
}
};
for (var name in buz) {
console.log(name)
console.log(buz[name])
console.log(buz[name]["fog"])
}