In JavaScript, there are three ways to traverse the object's property:
1.for/in. You can use the for/in statement to traverse the object's own property (Own Property) and the property inherited from the prototype object. Only the enumerable property will be traversed.
2.Object.keys(). You can pass objects as parameters into Object.keys(), and the Object.keys() statement will return an array composed of all property name strings. The Object.keys() statement returns only the (Own Property) and enumerable property of the object itself. This statement is only valid in the ECMAScript 5 standard.
3.Object.getOwnPropertyNames(). You can pass an object as a parameter into Object.getOwnPropertyNames(). Like Object.keys(), this statement will return an array composed of all property name strings. Unlike Object.keys(), the Object.getOwnPropertyNames() statement returns all objects' own property(Own Property) regardless of whether it is enumerable or not. This statement is only valid in the ECMAScript 5 standard.
Based on the above information, the following figure is summarized as follows:
experiment:
The code copy is as follows:
var o = {x:1, y:2};
var a = Object.create(o);
az = 3;
for(p in a){
console.log(p);
}//zxy
console.log(Object.keys(a));//["z"]
console.log(Object.getOwnPropertyNames(a));//["z"]