在ES5中如果有一个数组有很多的元素。我们可能需要使用数组的索引一个一个的取出来。
这个明显是比较麻烦的。
在ES6中就有了新的取数组中的元素方式
let arr = ['hello', 'world']
let [firstName, lastName] = arr
console.log(firstName, lastName)
如果有多个元素的话我只想取指定的第几个,而不取前面的值呢?
let arr = ['one', 'two', 'three', 'four', 'five']
// 如果这个时候我只要最后一个呢?怎么办呢?
let [,,,,lastName] = arr
console.log(lastName)