Object destructuring is a JavaScript feature that allows you to extract the properties of an object into variables. This can be used to make your code more concise and readable.
Object destructuring can be used with both literal objects and objects created with constructors.
The syntax for object destructuring is as follows:
const { property1, property2, ...rest } = object;
The { property1, property2, ...rest } part is called the destructuring pattern. The object is the object that you want to destructure.
The property1 and property2 are the names of the properties that you want to extract. The ...rest is an optional pattern that allows you to extract the remaining properties of the object into an array.
The following code destructures the person object and assigns the name and age properties to the name and age variables:
const { name, age } = person;
The name variable now contains the value of the name property of the person object. The age variable now contains the value of the age property of the person object.
Object destructuring can be used to make your code more concise and readable. It can also be used to make your code more efficient, by avoiding the need to use the . operator to access properties.