Destructuring Arrays and Objects in JavaScript ES6

Last Updated On Sunday 19th Dec 2021
  • Destructuring allows us to extract values from arrays and objects
  • We can store them in variables with a more convenient syntax.

Destructuring Arrays

	let [a, b, c, d] = [1, 2, 3, 4];

console.log(a); // 1
console.log(b); // 2
	

Destructuring Objects

	let me = {
    mobile: 'Samsung',
    laptop: 'Lenovo'
};
let {
    mobile,
    laptop
} = me;

console.log(mobile); // Samsung
console.log(laptop); // Lenovo