You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let me = {
name: 'lee',
age: 26
};
let {name: firstName, age: myAge} = me;
console.log(firstName, myAge);
解构时赋予默认值
let me = {
name: 'lee',
age: 26,
sexual: undefined
};
let {name = 'Lee', age = 27, sexual = 'male', weight = 56} = me;
console.log(name, age, sexual, weight);
对象的嵌套解构
let student = {
name:'jsPool',
age:20,
scores:{
math:95,
chinese:98,
english:93
}
};
let {name, age, scores: {
math,
english,
chinese
}} = student;
console.log(name, age, math, english, chinese);
展开语法
展开语法使用...三个点来操作,跟函数的剩余参数一样,都是三个点,但是用法不一样,不可混淆。
替换apply的调用
// 替代apply
let arr = [55, 100, 48, 32, 89];
let result = Math.min.apply(null, arr);
console.log(result);
// 使用...
let arr = [55, 100, 48, 32, 89];
let result = Math.min(...arr);
console.log(result);
代替concat
// 代替concat
let arr = [1, 2, 3];
let result = [4, 5, 6].concat(arr);
console.log(result);
let arr = [1, 2, 3];
let result = [4, 5, 6, ...arr];
console.log(result);
// 可以灵活的放到头部
let arr = [1, 2, 3];
let result = [...arr, 4, 5, 6];
console.log(result);
解构赋值
数组解构
在数组的解构赋值表达式中可以为数组的任意位置添加默认值,当指定位置的属性不存在或其值为 undefined 时使用默认值。
对象解构
展开语法
展开语法使用...三个点来操作,跟函数的剩余参数一样,都是三个点,但是用法不一样,不可混淆。
函数的剩余参数
函数的剩余参数也是...,注意区分
输出结果:
The text was updated successfully, but these errors were encountered: