destructuracion js code example
Example 1: destructure array javascript
var [first, second, ...rest] = ["Mercury", "Earth", ...planets, "Saturn"];
Example 2: how destructuring works in javascript
const objA = {
prop1: 'foo',
prop2: {
prop2a: 'bar',
prop2b: 'baz',
},
};
const { prop1, prop2: { prop2a, prop2b } } = objA;
console.log(prop1);
console.log(prop2a);
console.log(prop2b);
Example 3: javascript destructuring
const classDetails = {
strength: 78,
benches: 39,
blackBoard:1
}
const {strength:classStrength, benches:classBenches,blackBoard:classBlackBoard} = classDetails;
console.log(classStrength);
console.log(classBenches);
console.log(classBlackBoard);