展开操作符

[TOC]

#函数调用

将数组的值,展开后依次传给x, y, z

function fn(x, y, z) { };
let args = [1, 2, 3];
test(...args);

#展开数组

var arr1 = [1, 2, 3];
var arr2 = [4, 5, 6];

//以往方法
var arr3 = arr1.concat(arr2);

//ES6中
var arr4 = [...arr1, ...arr2];

#展开对象

let person = {name: 'aaron', sex: 'male'};
person = {...person, age: 30};
console.log(person);