js nested object destructuring code example
Example 1: object destructuring example
const hero = {
name: 'Batman',
realName: 'Bruce Wayne',
address: {
city: 'Gotham'
}
};
// Object destructuring:
const { realName, address: { city } } = hero;
city; // => 'Gotham'
Example 2: javascript nested array destructuring
let arr = [1, 2, 3, 4, [100, 200, 300], 5, 6, 7];
// nested array destructuring
const [a, , , , [, b, ,], , , ,] = arr;
console.log(a);
// expected output "1"
console.log(b);
// expected output "200"