• 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 8 months ago (04-02) 361 views 2 comments

What is a set?

ES6 adds a new data structure called set. 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. In other words, you can't get an index 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

We've been blogging that year
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