这俩等价
const numbers1 = [1, 2, 3, 4, 5];
const numbers2 = [ ...numbers1, 1, 2, 6,7,8]; // this will be [1, 2, 3, 4, 5, 1, 2, 6, 7, 8]
还可以作为可变参数供调用
function sum(...numbers) {
return numbers.reduce((accumulator, current) => {
return accumulator += current
});
};
sum(1,2) // 3
sum(1,2,3,4,5) // 15