本节知识点
- 展开运算符 … 他只能写在最后面,要是写在前面,后面的参数出不来.
- 这个就是为了方便扩展运算的。
举例
function addNumber(a, b, c, d, e) {
var numbers = [a, b, c, d, e];
return numbers.reduce((sum, item) => {
return sum + item;
}, 0)
}
console.log(addNumber(1, 2, 3, 4, 5));
function addNumber(...numbers) {
return numbers.reduce((sum, item) => {
return sum + item;
}, 0)
}
console.log(addNumber(1, 2, 3, 4, 5));
对象解析
let expense = {
type: "es6",
amount: "45"
};
let a = expense.type;
let b = expense.amount;
console.log(a, b);
const { type, amount } = expense;
console.log(type);
console.log(amount);
let expense = {
type: "es6",
amount: "45"
};
let a = expense.type;
let b = expense.amount;
function fileSammary(obj) {
return `${obj.type}+${obj.amount}`;
}
console.log(fileSammary(expense)); //结果就是es6+45
let arr = [1, 2, 3, 4, 5, 6];
const a = [...arr];
console.log(a);