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

Some basic explanations of JavaScript

巴扎黑
Release: 2017-07-20 14:36:30
Original
1297 people have browsed it

The spread operator is represented by three dots. Its function is to expand an array or array-like object into a series of values ​​separated by commas. The spread operator has several functions. Let me explain them one by one! ! !

1, expand the array

//Expand the array let a = [1,2,3,4,5],b = [...a,6,7];console. log(b);//Printed value [1, 2, 3, 4, 5, 6, 7]

2, copy of the array

//Array Copy var c = [1, 2, 3]; var d = [...c]; d.push(4); console.log(d);//Printed value [1, 2, 3, 4 ]

3. Merging of arrays

//Merge of arrays var j = [7, 1, 2]; var k = [5, 0, 8]; j = [...k, ...j];console.log(j)//Printed value [5, 0, 8, 7, 1, 2]

Four, expand function Call

//Expand function call function fn(a,b,c,d){
console.log(a+b+c+d);}var p=[1,9, 3,,6];let result=fn(5,...p);Open function call //The printed value 18

The spread operator (spread) is three dots ( ...), converts an array||array-like||string into a comma-separated sequence. This guy is used to operate on arrays and take out all the things in the array

Extension operator

let zzz=[2,4,6];
console.log(zzz);//[2, 4, 6]
console.log(...zzz);//2 4 6

let a=[1,2,3];
let b=[...a,4,5,6];
console.log(b);//1,2,3,4,5,6

let [a,b,...c]=[1,2,3,4,5];
console.log(a,b);//1 2
console.log(c);//[3, 4, 5]
Copy after login

Arrow function

let say333=()=>{
    console.log("333");//333
}
say333();

(name)=>{
    console.log(name);
}

(a,b)=>{
    return a+b;
}

(a,b)=> a+b;
Copy after login

Parameter default value, remaining parameters , extended parameters

let aa=(name='wwrs')=>{
        console.log(`Hello ${name}`);
    }
    aa();//Hello wwrs
    aa('sss');//Hello sss
    
    
let bb=(a,b,c)=>{
        console.log(a+b+c);//9
    }
    let dd=[2,3,4];
    bb(...dd);
    
    
let he=(a,b,c,d)=>{
    console.log(a+b+c+d);//10
}
he(1,2,3,4)

let he1=(s,j,...shi)=>{
    console.log(shi);//[3, 4]
}
he1(1,2,3,4)
Copy after login

The above is the detailed content of Some basic explanations of JavaScript. 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