5 ways to traverse the object properties, the order rules

1, in for ...
for ... in loop through the object itself and inherited enumerable property (without Symbol)

2, Object.keys (obj)
Object.keys returns an array, including the object itself (not inherited) all enumerated attribute (attribute excluding Symbol) key name

. 3, Object.getOwnPropertyNames (obj)
Object.getOwnPropertyNames Returns an array containing all their properties (excluding Symbol attributes, including but not enumerated attribute itself) key name

4, Object.getOwnPropertySymbols (obj)
Object.getOwnPropertySymbols returns an array containing all objects themselves familiar Symbol keys

5, Reflect.ownKeys (obj)
Reflect.ownKeys returns an array containing all the object keys themselves, regardless of the key name is Symbol or string, whether or not enumerable


5 or more traverse the object key name, will follow the rules of the same order of traversal property

- said first traversing Numerical keys, arranged in ascending order of value.
- Secondly, the string through all keys in ascending order according to the added time.
Symbol finally through all keys, arranged in ascending order of addition time

1 Reflect.ownKeys({ [Symbol()]:0, b:0, 10:0, 2:0, a:0 })
2 //["2", "10", "b", "a", Symbol()]

 

Guess you like

Origin www.cnblogs.com/hongding/p/11108734.html