1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| var names = ["abc", "cba", "nba", "xixiha"] var obj = { name: "why", age:18, height:1.88 }
var [name1, name2, name3] = names console.log(name1, name2, name3)
var [name1, , name3] = names
var [name1, name2, ...newNames] = names
var [name1, name2, name3 = "default"] = names
var {name, age, height } = obj console.log(name, age, height)
var {height, name, age} = obj console.log(name, age, height)
var {height:wHeight, name:nName, age:wAge} = obj console.log(wHeight, nName, wAge)
var { height:wHeight, name:nName, age:wAge, adress:wAddress="CN"} = obj
|