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

How to use the three points 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 how to use the three points in es6, with a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.

Usage: 1, merge array, syntax is "[... arr1,... arr2]"; 2, copy array object, syntax is "name= [... array object]"; 3, string to character array, syntax is "[... string object]"; 4, deconstruct variables, syntax is "[variable object,... name] = value".

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

What is the usage of the three dots in es6

The extension operator (spread) is three dots (... Is a new operator for ES6 that does a lot of things, such as converting an array to a comma-separated sequence of parameters Two types of extension operators for objects and operators for arrays are commonly used in application scenarios.

The functions are as follows:

1. Gets the maximum value of the array.

Routine: Math.max (1, 2, 3)

Written by: Math.max (… Is equivalent to the example above.

two。 Call method

Function sum (a _ r _ b) {console.log (a _ r _ b) / / 5} sum (. [2p _ 3])

The output is as follows:

3. Join array

Var arr1 = [0,1,2]; var arr2 = [3,4,5]; arr1.push (... arr2)

Results the array elements are 0,1,2,3,4,5.

4. Join array

Var arr1 = ['asides,' b']; var arr2 = ['c']; var arr3 = ['dudes,' e']; [... arr1,... arr2,... arr3]

The connected array elements are: a, b, c, d, e

5. The string is converted to a real array

[... 'hello'] / /

The result is:

6. Convert the class array to a real array and remove the weight

[. New Set ([1, 2, 3, 3])] / /

New Set returns an array of classes,... Convert a class array to a real array

7. Extended algorithm

Let map = new Map ([[1, 'one'], [2,' two'], [3, 'three'],]); let arr = [... map.keys ()]; / / [1,2,3]

When writing vue projects, since you don't know how many params there are, you can directly params:param.data or params: {undefined

.. param.data} return axios ({method: param.type, url: value.prefix + param.url + value.postfix, params: {. Param.data / / expand the array}}) Thank you for reading this article carefully. I hope the article "how to use the three points in es6" shared by the editor will be helpful to you. At the same time, I hope you will support it. Pay attention to the industry information channel, more related knowledge is waiting for you to learn!

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