遍历

属性遍历:

1、for...in:包含原型属性

1)[[Enumberable]] = true

1)Object.hasOwnProperty() 筛出原型属性

2、Object.keys(obj);

var obj = {
  name:'aa',
  age: 22
}
var s = Object.keys(obj);
console.log(s); //  ["name", "age"]

3、Object.getOwnPropertyName(obj) 遍历所有可枚举不能枚举的属性

var person = {
  name:'xa',
  age:34,
  sex:'nv'
}
Object.defineProperty(person,"name",{
  enumerable:false
})
console.log(Object.getOwnPropertyNames(person)) // ["name", "age", "sex"]
posted @ 2019-12-16 21:39  雨夜稻草  阅读(161)  评论(0编辑  收藏  举报