Ads by ProfitSence
Close

Destructuring Arrays and Objects in JavaScript ES6

Last Updated on Wednesday 5th Oct 2022
  • 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