Destructuring assignment of ES6 objects

Copy the entire object into a variable

let {...obj} = {foo: 'aaa', bar: 'bbb'};

Get a value in the object

let {bar} = {foo: 'aaa', bar: 'bbb'};
console.log(bar )  //  bbb

Get a value in the object, the variable name is different from the attribute name

let {foo: baz} = {foo: 'aaa', bar: 'bbb'};
console.log(baz) // aaa

Get the contents of the object array

let obj = {
    p:['hello',{y:  'world'}]
}
let {p:[x, { y}]} = obj

console.log(x) // hello
console.log(y) // world

 

Guess you like

Origin blog.csdn.net/qq_34312604/article/details/108509680