Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How to destructuring values from an nested object in javascript?

var personsInfo = {
    company: 'sp-coder',
    persons: [{
        id: 1,
        name: 'Adil',
        friedsList: {
            friend1: 'Nabil',
            friend2: 'Habib'
        }
    }, {
        id: 2,
        name: 'Arif',
        friedsList: {
            friend1: 'alvi',
            friend2: 'avi'
        }
    }]
};

const { friend1, friend2 } = personsInfo.persons[0].friedsList;
console.log(friend1, friend2);
// Expected Output: Nabil Habib
Source by medium.com #
 
PREVIOUS NEXT
Tagged: #How #destructuring #values #nested #object
ADD COMMENT
Topic
Name
3+6 =