我们es5时,获取数组里面的值一般都是使用下标
如
// 数组
let arr = ['a','b','c']
let a = arr[0]
let b = arr[1]
let c = arr[2]
console.log(a)//a
console.log(b)//b
console.log(c)//c
// 对象
let personle = {
name:'lin',
age : 18
}
let age = personle.age
let name= personle.name
age = 19
console.log(age)//19
console.log(name)//lin
console.log(personle.age)//18
而使用es6的解构后
// 数组
let arr = ['a','b','c']
let [a,b,c] = arr
console.log(a)//a
console.log(b)//b
console.log(c)//c
// 对象
let personle = {
name:'lin',
age : 18
}
// 对象解构
let {name,age} = personle
age = 19
console.log(age)//19
console.log(name)//lin
console.log(personle.age)//18