Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the methods of traversing objects in es6

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the es6 traversal object method has what related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that you will have something to gain after reading this es6 traversal object method, let's take a look.

Method: 1, use "Object.keys (obj)" to traverse the object, returning an array of key names including all the enumerable attributes of the object itself; 2, traverse the object with "Reflect.ownKeys (obj)" and return an array containing all the key names of the object itself; 3, loop through the object with "for in", and so on.

This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.

What is the method of es6 traversing the object

1. For... In

For... The in loop iterates through the object's own and inherited enumerable properties (excluding the Symbol property).

2. Object.keys (obj)

Object.keys returns an array that includes the key names of all enumerable properties (excluding the Symbol property) of the object itself (excluding inheritance).

3. Object.getOwnPropertyNames (obj)

Object.getOwnPropertyNames returns an array containing the key names of all the properties of the object itself (excluding the Symbol property, but including non-enumerable properties).

4. Object.getOwnPropertySymbols (obj)

Object.getOwnPropertySymbols returns an array containing the key names of all the Symbol properties of the object itself.

5. Reflect.ownKeys (obj)

Reflect.ownKeys returns an array containing all the key names of the object itself, whether the key name is Symbol or a string, or whether it can be enumerated or not.

The above five methods traverse the key names of objects and all follow the same order rules for traversing attributes.

First, iterate through all the numeric keys and arrange them in ascending order.

Secondly, all the string keys are traversed and sorted in ascending order of adding time.

Finally, iterate through all the Symbol keys and sort them in ascending order by adding time.

Reflect.ownKeys ({[Symbol ()]: 0, Symbol 0, 10:0, 2:0, aSymbol 0}) / / ['2 steps,'10 seconds, 'baths,' aways, Symbol ()] about "what are the methods of traversing objects in es6?" that's all for this article. Thank you for reading! I believe you all have a certain understanding of the knowledge of "what are the methods of es6 traversing objects". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report