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

Are set types ordered in es6?

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

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge that the set type in es6 is orderly, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe that after reading this es6, the set type in this article will have something to gain, let's take a look at it.

Set types are ordered in es6. The set type is a new ordered list collection in es6, which contains some independent non-repeating values; the traversal order of set is the insertion order, and when a function list call saved by set is called in the specified order, so the set type is ordered.

This article operating environment: windows10 system, Vue2.9.6 version, DELL G3 computer.

Is the set type in es6 ordered?

Is orderly, you can find the answer in the official Set, the traversal order of the Set is the insertion order.

This feature is sometimes useful, such as using Set to save a list of callback functions that are guaranteed to be called in the order in which they are added.

Basic concept

The new Set type added by ES6 is an ordered list with some non-repeating values that are independent of each other.

* the inner part of the Set collection is judged by the Object.is () method as to whether there is duplication between members.

Set is an ordered list collection added by ES6 and does not contain duplicates. Previously, we used to use objects (Object) or arrays (Array) to implement collections without duplicates. However, the object will toString () the key, which will cause some key to accidentally overwrite the previous data; if the key itself is an object, toString () will not get the desired result, as follows:

JSvar o = {}; var key1 = 2 key2 var key2 = {toString: function () {return 2}}; var key3 = {x: 1}; var key4 = {y: 2}; o [key1] = 1 key2 [key2] = 3 [key4] = 4 key2 / o: Object {2: 2, [object Object]: 4}

Arrays can hold any type of data, but data deweighting needs to be implemented on your own.

Set supports the add (item) method, which is used to add any type of element to the Set and automatically ignore it if it has been added; the has (item) method is used to detect whether the specified element exists in the Set; the delete (item) method is used to delete the specified element from the Set; and clear () is used to empty the Set; to get the size attribute for the length of the Set collection. As follows:

JSvar set = new Set (); set.add (window); set.has (window); / / trueset.size; / / 1set.add (window); set.add (1); set.size; / / 2set.delete (window); set.has (window); / / falseset.clear (); set.size; / / 0

This is the end of the article on "is the type of set in es6 ordered?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "is the type of set in es6 orderly?". 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