Destructuring
Sat Nov 26 2022 16:01:18 GMT+0000 (Coordinated Universal Time)
Saved by
[deleted user]
#javascript
// Object destructuring
const person = {
name: 'John',
age: 32,
city: 'New York',
country: 'USA'
};
const { name, age } = person;
// Object destructuring with alias
const { name: firstName, age: years } = person;
// Array destructuring
const fruits = ['apple', 'banana', 'orange'];
const [first, second, third] = fruits;
content_copyCOPY
Comments