This time I will show you how to use the ES6 expansion operator. The expansion operator has the following four functions. This article will give you a good analysis.
1. Expand the array
//展开数组 let a = [1,2,3,4,5], b = [...a,6,7]; console.log(b); //打印出来的值[1, 2, 3, 4, 5, 6, 7]
2. Copy the array
//数组的拷贝 var c = [1, 2, 3]; var d = [...c]; d.push(4); console.log(d); //打印出来的值[1, 2, 3, 4]
3. Merge the array
//数组的合并 var j = [7, 1, 2]; var k = [5, 0, 8]; j = [...k, ...j]; console.log(j) //打印出来的值[5, 0, 8, 7, 1, 2]
4. Calling the spread function
//展开函数调用 function fn(a,b,c,d){ console.log(a+b+c+d); } var p=[1,9,3,,6]; let result=fn(5,...p);开函数的调用 //打印出来的值18
The spread operator (spread) is three dots (...), which converts an array ||like array| |Convert a string to a comma-separated sequence. This guy is used to operate arrays and take out all the things in the array
I believe you have mastered the method after reading the above introduction. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Related reading:
js implements imitation window system calendar effect
How can JS click to jump to login Personal email
There are several ways to implement chain operations in PHP
The above is the detailed content of How to use the ES6 spread operator. For more information, please follow other related articles on the PHP Chinese website!