var obj = { "prop1": "v1" };
Object.defineProperty(obj,"prop2",{ value: "v2",writable: false });
console.log(Object.keys(obj).length); //output:1
console.log(Object.getOwnPropertyNames(obj).length); :2
console.log(Object.keys(obj)); //output:Array[1] => [0: "prop1"]
console.log(Object.getOwnPropertyNames(obj)); :Array[2] => [0: "prop1",1: "prop2"]
true });
console.log(obj.hasOwnProperty("prop1")); output: true
console.log(obj.hasOwnProperty("prop2")); output: true
console.log(obj.propertyIsEnumerable("prop1")); output: true
console.log(obj.propertyIsEnumerable("prop2")); output: false
console.log('prop1' in obj); output: true
console.log('prop2' output: true
for (var item in obj) {
console.log(item);
}
output:prop1
Object.getOwnPropertyNames(obj)) {
console.log(Object.getOwnPropertyNames(obj)[item]);
}
ouput:[prop1,prop2]