Object Destructuring Assignment
Object destructuring assignment allows you to extract values from objects and assign them to variables with a concise syntax.
const person = {
name: 'John Doe',
age: 30,
address: {
street: '123 Main St',
city: 'New York'
}
};
const { name, age, address: { city } } = person;
console.log(name, age, city);
// Output: John Doe 30 New York
In the example above, object destructuring is used to extract the name, age, and city properties from the person object. The address property is further destructured to extract the city property from the nested object.
No comments:
Post a Comment