So, you want to destructure an object but the property name is already assigned to another variable in the same scope or you just don't like the property name?
A property can be destructured from an object and assigned to a variable with a different name using the following syntax:
const personal = 'Something personal...'
const info = {
personal: 'pjately.dev',
social: {
twitter: 'twitter.com/pjately',
github: 'github.com/pranjaljately',
},
}
const { personal: profile } = info
console.log(profile); // pjately.dev
Short, simple and sweet.
Peace.
Top comments (0)