ES6允许按照一定模式从数组和对象中提取值,对变量进行赋值,也才被称为解构赋值
1、数组的解构
const F4 = ['小沈阳','刘能','赵四','宋小宝'];
let [xiao,liu,zhao,song] = F4;
console.log(xiao);//小沈阳
console.log(xiao);//刘能
console.log(xiao);//赵四
console.log(xiao);//宋小宝
2、对象的解构
const Zhao = {
name:'赵本山',
age:'不详',
xiaopin:function(){
console.log("我可以演小品");
}
}
let {name,age,xiaopin} = Zhao;
console.log(name);
console.log(age);
console.log(xiaopin);
xiaopin();
参考:尚硅谷视频https://www.bilibili.com/video/BV1uK411H7on?p=7