• Welcome to the eight year blog, I'm glad to meet you at the right age!
  • Due to the theme, QQ login partners will display the default avatar in the comments. Please go to the personal center and upload the avatar again.

Understanding the set structure in ES6

Code Notes barben 6 months ago (04-02) 245 views 2 comments

What is a set?

A new data structure is called ES6. It is similar to an array, but it has no duplicate values of its own.

What are the parameters of new set()?

1. Array

2. Objects similar to arrays
For example, the NodeList collection returned by Dom operation, and the arguments object inside the function.

 //NodeList object 
 document. Queryselectorall ('p '); 
 / / arguments object 
 function args() {return arguments; 

3. It can even be a string

Points for attention

1. In the set data structure, there is a size attribute, which can be regarded as the length in the array.

2. The set data structure has no key name, that is, you can't use the index to get a certain value like an array.

Convert the set structure to an array

Although a set is similar to an array, many methods in an array cannot be used on a set. So sometimes you need to convert it to an array.

use Array.from method
This method is used to convert two types of objects into real arrays:
·Array like object
·Traversable objects (including new data structures set and map in ES6)

For a detailed description of array. From, click here

Method of set instance

Eight blogs that year, we've been there all the time
If the author does not indicate the original article, please indicate the link and source of this article
Understanding the set structure in ES6 - https://www.barben.cn/code/707.html
Like it( three )
Post my comments
Cancel comment
expression Mapping Bold Strikethrough Center Italics

You need to bring your nickname and email with you in the year of eight!

  • Nickname (required)
  • Email address (required)
  • website