一、解构赋值
//对象
const course = {
name:'es6',
price: 200
};
//按照正常写法,我们会这样来写
// const name = course.name;
// const price = course.price;
//es6的简单写法
const {name,price} = course;
console.log(name,price)
//数组
const courseArr = ['es6','es7','es8']
// const a = courseArr[0]
// const b = courseArr[1]
// const c = courseArr[2]
const [a,b,c] courseArr
console.log(a,b,c)
//复杂的对象
const course = {
name1:'es6',
price: 200,
teacher:{
name:'mack',
age:18
}
};
const {
name1,
price,
teacher:{
name,age
}
} = course
console.log(name1,price,name,age)