Home  >  Article  >  Web Front-end  >  How to use the three-dot operator

How to use the three-dot operator

一个新手
一个新手Original
2017-10-12 09:23:543350browse

Let’s first look at an example of using the three-dot operator under the es6 specification:


let fun=function(a,...list){
    console.log(a,list);
};
fun('0','a','b','c');//0 [a,b,c]

As you can see from the above, we can now dynamically set the parameters of the parameters when defining the function object. Count: the first parameter a is an ordinary parameter (ignored),

You can see that there are three dots "..." in front of the second parameter list. There are two of this writing method in the es6 specification. Purpose

1. Used as a parameter.

2 . Used as a spread operator.

● Three points--as parameters:


let fun1='a','b','c');fun1(1,2);=1,2,3);fun2(1);=[x,...y]=[1,2,3=[1,2,3];

● Three points--as extended operations Symbols used:


let arr=[1,2,3=[2,31,...a,4);=document.querySelectorAll('p'console.log(...ps);= Set([1,2,3,3= Map([[1,'a'],[2,'b'],[3,'c'[...map.values];'wbiokr'];='abc''aaa',...str,'ccc'];


The above is the detailed content of How to use the three-dot operator. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn