Kevin

Kevin

【JS Destructuring Assignment】Various Destructuring Assignments

let obj = {
    name: 'Xiao Ming',
    age: 18,
    hobby: ['singing', 'dancing'],
    game: { pvz: 'Senior Player' }
}

Assign Default Value When Destructuring Nonexistent Property#

// If ambition does not exist in obj, assign it the string "scientist"
let {ambition='scientist', name} = obj
console.log(ambition); // scientist
console.log(name); // Xiao Ming

Destructuring Property from Object's Object Property#

let {game: {pvz}} = obj
console.log(pvz); // Senior Player
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.