extension Operators ...
1. Array extension operators convert an array to a comma-delimited sequence of arguments
Console.log (... [//1,2,3])
[' A ', ' B ',... [1,3]]//a,b,1,3
2. Extended Operations for function calls
function push (A, arr) {
A.push (... arr.);
}
****************************************************************************************
function Add (A, b) {
return a+b;
}
var arr=[1,8];
Add (... arr);
****************************************************************************************
function Add (x,y,z,n,m) {
return x+y+z+n+m;
}
var a = [[+]
Add (1,... a,3);
3. Apply extension operator instead of array
Es5
Math.max.apply (null, [1,3,4,5]);
Es6
Math.max (... [1,2,3,5])
Inserts an array into the tail of an array
1) Array.prototype.push (ARR1,ARR2);
2) arr1 = Arr1.concat (ARR2);
3) Arr1.push (... arr2);
Copying an array
arr1 = Arr.concat ()
arr1 = Arr.splice (0)
ARR1 = [... arr]
Structure Assignment
const [A, ... b] = [1,2,3,4]//a=1 b=[2,3,4]
The extension can only be used in the last
4. Convert Strings to arrays
[... ' This is str ']; ["T", "H", "I", "s", "", "I", "s", "", "s", "T", "R"]
Correctly handle strings that contain uicode codes
' x\ud83d\ude80y '. Length//4
[... ' x\ud83d\ude80y '].length//3
Invert string
Let str = ' x\ud83d\ude80y ';
Str.split ("). Reverse (). Join (')
' Y\ude80\ud83dx '
[... str].reverse (). Join (')
' y\ud83d\ude80x '
5. As long as the class array structure of the iterator interface is implemented, the extension operator can be converted to a true array
[... Nodelist]
ES6 Learning Notes (i) Array extension