How to rename fields when using object destructuring

Understand how to rename object fields when destructuring

Sometimes an object contains some attribute set, but you wantdamageIt changed the name.

For example, some function names do not conform to your naming convention, or you already have a variable with that name.

You can use the following syntax to rename one of the fields:

const person = {
  firstName: 'Tom',
  lastName: 'Cruise'
}

const { firstName: name, lastName } = person

name //Tom lastName //Cruise

Download mine for freeJavaScript beginner's manual


More js tutorials: