Home > Web Front-end > JS Tutorial > body text

How to use the three-dot operator

一个新手
Release: 2017-10-12 09:23:54
Original
3304 people have browsed it

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]
Copy after login

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];
Copy after login

● 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'];
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!