gistfile1.txt /** * Created by Administrator on 2017/11/10. */console.log(1,...[2,3,4],5) //1 2 3 4 5function add(x, y) { return x+y}var numbers = [4,38]a = add(...numbers)console.log(a) // 42function f(x, y, z) {}var a =[0,1,2]f(...a) //ok
/** * Created by Administrator on 2017/11/10. */ console.log(1,...[2,3,4],5) //1 2 3 4 5 function add(x, y) { return x+y } var numbers = [4,38] a = add(...numbers) console.log(a) // 42 function f(x, y, z) { } var a =[0,1,2] f(...a) //ok 由于扩展运算符可以展开数组,所以不再需要apply方法,将数组转为函数的参数了。 var a=[1,2,3] var b = [2,3,4] var c = [...a,...b] console.log(c) // 42 const [first,...end] = [1,2,3,4,5] // const [first,...end] = "fooo" console.log(first) //f 1 console.log(end) //[ 'o', 'o', 'o' ] [ 2, 3, 4, 5 ] // console.log(endend) a = [..."helllo"] //扩展运算符还可以将字符串转为真正的数组。 console.log(a) //[ 'h', 'e', 'l', 'l', 'l', 'o' ]