How Does Array and Object Destructuring Work?
September 10, 2024About 1 min
How Does Array and Object Destructuring Work? 관련
The JavaScript Interview Prep Handbook – Essential Topics to Know + Code Examples
JavaScript is a widely used language in web development and powers interactive features of virtually every website out there. JavaScript makes it possible to create dynamic web pages and is very versatile. JavaScript remains one of the most in-demand programming languages in 2024. Many companies are looking for proficiency in...
The JavaScript Interview Prep Handbook – Essential Topics to Know + Code Examples
JavaScript is a widely used language in web development and powers interactive features of virtually every website out there. JavaScript makes it possible to create dynamic web pages and is very versatile. JavaScript remains one of the most in-demand programming languages in 2024. Many companies are looking for proficiency in...
Similar to the spread operator, you can spread out elements of an array or an object into individual variables.
const arr = [1, 2, 3];
const [a, b, c] = arr;
console.log(a); // 1
console.log(b); // 2
console.log(c); // 3
This is the same for objects:
const obj = { name: 'kunal', age: 22, gender: 'male' };
const {name, age, gender} = obj;
console.log(name); // kunal
console.log(age); // 22
console.log(gender); // male