Es6 several ways to traverse the object

ES6 There are five ways to traverse the object's properties.
1)for...in

for ... in loop through the object itself and inherited enumerable property (excluding Symbol Properties).
2)Object.keys(obj)

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

Object.getOwnPropertyNames returns an array containing all the properties of the object itself (excluding Symbol properties, including but not enumerated attribute).
4)Object.getOwnPropertySymbols(obj)

Object.getOwnPropertySymbols returns an array containing all the object itself Symbol property.
5)Reflect.ownKeys(obj)

Reflect.ownKeys returns an array containing all the properties of the object itself, whether the attribute name is Symbol or string, whether or not enumerable.

// /////Object.keys traversal attribute ///////// 
the let {A obj =:. 1, B: 2, C:. 3 };
Object.keys (obj); // [ "A", "B", "C"] Returns an array of object properties

 

// ///////Object.keys ///////// traversal value 
the let {A obj =:. 1, B: 2, C: function () {}};
Object.values (obj); // [. 1, 2, F] Back object property value array of values


// /////Object.entries traversal key to //////// 
the let {A obj =:. 1, B: 2, C: function () {}};
Object.entries (obj); // // [[ 'A',. 1], [ 'B', 2], [ 'C', F] returns the object key array

// /////Object.getOwnPropertyNames traversal attribute (not enumerable enumeration +) ///////// 
the let {A obj =:. 1, B: 2, C: function () {}};
Object.getOwnPropertyNames (obj); // // [ "A", "B", "C"] Returns an array of objects comprises attributes not enumerable

 

 

Guess you like

Origin www.cnblogs.com/agen-su/p/11790315.html