Home > Article > Web Front-end > Some basic explanations of JavaScript
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
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]
let say333=()=>{ console.log("333");//333 } say333(); (name)=>{ console.log(name); } (a,b)=>{ return a+b; } (a,b)=> a+b;
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)
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!