Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How to use JavaScript map() method to access nested objects?

//access value by using map
var personsInfo = {
    company: 'sp-coder',
    persons: [{
        id: 1,
        name: 'Adil'
    }, {
        id: 2,
        name: 'Arif'
    }]
};
const getNames = personsInfo.persons.map((data) => data.name);
console.log(getNames);
//Expected Output is [ 'Adil', 'Arif' ]
 
PREVIOUS NEXT
Tagged: #How #JavaScript #method #access #nested
ADD COMMENT
Topic
Name
4+3 =