destructuring array and object from a nested object

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

showing results for - "destructuring array and object from a nested object"
Marlene
03 Mar 2016
1// destructuring array & nested array & combine array into single array
2let person = ["John", "Sandy", "Sam", ["Mike", "Max"], "Diego", "Paul"];
3// empty comma is like skipping array index. I skipped "Sam"
4const [a, b, , c, ...d] = person;
5
6let friend = [d, "Tom", "Jerry"] 
7let newFriend = [...d, "Tom", "Jerry"]
8
9console.log(a); // output: "John"
10console.log(b); // output: "Sandy"
11console.log(c); // output: [ "Mike", "Max" ]
12console.log(d); // output: ["Diego", "Paul"]
13console.log(friend); // output: [ [ 'Diego', 'Paul' ], 'Tom', 'Jerry' ]
14console.log(newFriend); // output: [ 'Diego', 'Paul', 'Tom', 'Jerry' ]
15
Malia
18 Aug 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}
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
Maria
04 Jan 2017
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
Nicolò
29 Aug 2016
1const user = {  id: 339,  name: 'Fred',  age: 42};
2const {name} = user;
3console.log(name); //Expected output: fred
queries leading to this page
how to destructure property of nested objects in javascriptupdate nested object destructuring javascriptdestructuring object within array withing iterator javascriptnested object destructuring javascriptdestructuring nested objects javascriptobject destructuring nestedjavascript destructuring assignment nestednested destructuring javascriptjavascript object destructuring nested variable name in arraynested object destructuringdestructuring nested objectsdestructure nested javascript objectdestructure nesteddeconstructing nested object javasciptjavascript nested destructuringcan you do nested destructuringarray destructuring withing iterator javascriptjs destructure nested objectdestructuring deep nested objectsjavascript info nested destructuring destructuring nested array of objectsget nested value form object destructuring javascripthow to destructure nested objectsget nested destructuring javascripthow to destructuring values from an nested object in javascript 3fjs deconstruct nested objecthow to access nested array in destructuringdestructuring a single element of an arrayjs object destructuring nested in arrayhow to destructure nested object javascriptnested object destructuring in javascriptjs object destructuring nested object and insert in arrayjs destructuring nested objectes6 parameter destructuring nested objectjavascript nested array destructuringdestructuring object from a nested objectjavascript destructuring nested object with checkdeconstruct nested object javascriptobject destructuring in function argument nestedobject destructuring for nesteddestructuring nested objects javajs array destructuring by 2how to destructure a nested objectdestructuring javascript nested objectdestructure nested array of objects javascriptdestructuring nested object destructuring object inside arrayobject destructing nestedaccess nested object key es6 destructuringdestructure nested array of objects in typescriptjs object destructuring nesteddestructuring in javascript nested objectdestructure a nested objectjavascript destructuring nested object default valuereact object destructuring with nested objectsusing destructuring for nested objectsjs destructuring two objectsdestructuring a nested objectdestructuring nested objects undefineddestructure nested jsonhow to deconstruct nested objectdestructuring nested objects in reacthow to destructuring nested object value in javascript 3fjavascript deconstruct nested objectnested destructuring in jsnested destructurehow to use object destructuring with a nested object in javascripthow to access nested object key es6 destructurenested array destructuringdestructuring an object inside of another one typescriptehow to destructuring nested object in javascriptdestructure nested object in array javascriptdestructure and return two items in array of objectnested object destructuring in reactjavascript destructure nested objecthow to destructure nested objects in javascriptdestructuring array and object from a nested objectdestructure nested object typescriptdestruct nested object inside objectdesstructurign nested objectdestructure nested objectnested destructure javascriptjs nested destructuringjavascript object nested destructuringnested object destructuring javascript spreadnested destructuringhow to destructure nested objectnested destructuring jsjavascript destructure nested arraydeconstruct nested object javacript destructure nested object javascriptdestructuring nested array javascripthow to desctucture new array in nested objectnested object and array destructuringdeconstruct array inside object javascriptnested array destructuring javascriptjavascript destructuring nested objectdestructuring array and object from a nested object