https://www.cnblogs.com/sunidol/p/11463600.html
Object
defineProperty
Object.defineProperty(
obj, "age",
{ value:"forever 18", enumerable:false }
);
getOwnPorpertyNames,不可枚举也可以遍历出来,返回数组,元素是字符
let obj=[5,55,555]
Object.getOwnPropertyNames(obj)//["0", "1", "2", "length"]
keys,values都是自身的且必须可枚举,返回数组,元素是字符
Object.keys(obj)//["0", "1", "2"]
obj
hasOwnProperty() 自身且,自身如果不可枚举也返回true。
for in
继承的也可以遍历出来,但是必须可以枚举。
Array.prototype.age=18
Object.prototype.name='ldx'
let arr = [3,33,33]
console.log(arr.hasOwnProperty('length'));//true
for(let key in arr){
console.log(key)
}// 0 1 2 age name