destructuring object from a nested object

Solutions on MaxInterview for destructuring object from a nested object by the best coders in the world

showing results for - "destructuring object from a nested object"
Elisa
13 Oct 2019
1const person = {
2    name: 'labib',
3    age: 22,
4    job: 'web-developer',
5    frieds: ['ahsik', 'abir', 'alvi', 'hanafi'],
6    childList: {
7        firstChild: 'Salman',
8        secondChild: 'Rafi',
9        thirdChild: 'Anfi'
10    }
11}
12
13//simple destructuring
14const { name, age, job } = person;
15console.log(name, age, job);
16//Expected output: labib 22 web-developer
Leon
04 Mar 2016
1const person = {
2    name: 'labib',
3    age: 22,
4    job: 'web-developer',
5    frieds: ['ahsik', 'abir', 'alvi', 'hanafi'],
6    childList: {
7        firstChild: 'Salman',
8        secondChild: 'Rafi',
9        thirdChild: 'Anfi'
10    }
11}
12const { frieds: [a, b, c] } = person; //array destructuring from a nested object 
13console.log(a, b, c);
14//expected output: ahsik abir alvi;
15const { childList: { firstChild, secondChild } } = person; //object destructuring from a nested object
16console.log(firstChild, secondChild)
17//expected output:Salman Rafi
Alessandra
17 Oct 2018
1const person = {
2    firstName: 'Adil',
3    lastName: 'Arif',
4    age: 25,
5    job: 'web-developer',
6    love: 'coding',
7    friedsList: {
8        friend1: 'Abir',
9        friend2: 'Adnan'
10    }
11}
12const { friend1, friend2 } = person.friedsList;
13console.log(friend1, friend2);
14//Expected output: Abir Adnan
Carl
31 Sep 2020
1const user = {  id: 339,  name: 'Fred',  age: 42};
2const {name} = user;
3console.log(name); //Expected output: fred
queries leading to this page
js destructuring nested objectnested destructuring javascriptjavascript nested array destructuringnested destructuringdestructuring an object inside of another one typescriptereact object destructuring with nested objectsobject destructuring in function argument nestednested array destructuring javascripthow to destructure nested objectdestructure a nested objecthow to desctucture new array in nested objectdestructuring array and object from a nested objectobject destructing nestedjavascript nested destructuringdestructure nested array of objects in typescriptjavascript destructure nested arrayobject destructuring for nestedhow to deconstruct nested objectinner property object destructuringhow to destructuring nested object value in javascript 3fjs destructure nested objectnested object destructuringdeconstruct nested object javacript destructure nestednested object destructuring javascriptdestructuring nested objects javaupdate nested object destructuring javascriptjavascript destructuring assignment nestedcan you do nested destructuringdestructure nested object javascriptdestructuring nested objects javascriptjavascript object nested destructuringnested object destructuring in reacthow to destructure nested objectsget nested destructuring javascriptjavascript deconstruct nested objectdestructuring object from a nested objectnested object and array destructuringdestructuring from two objectsjavascript destructure nested objectget nested value form object destructuring javascriptdeconstruct nested object javascriptnested array destructuringdestructuring nested array javascriptdestructuring nested array of objectsdestructure nested object typescriptdestructuring nested objects in reactdestructuring javascript nested objectdestructure nested objectdestructure nested jsondestructure nested object in array javascriptnested object destructuring in javascriptjs nested destructuringhow to destructuring values from an nested object in javascript 3fdestructuring nested objectsdestructuring object from a nested object