Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

array destructuring by using spread operator from a nested object in javascript

const person = {
    name: 'labib',
    age: 22,
    job: 'web-developer',
    frieds: ['ahsik', 'abir', 'alvi', 'hanafi'],
    childList: {
        firstChild: 'Salman',
        secondChild: 'Rafi',
        thirdChild: 'Anfi'
    }
}
const { frieds: [...a] } = person;
console.log(...a);
//Expected output:ahsik abir alvi hanafi
 
PREVIOUS NEXT
Tagged: #array #destructuring #spread #operator #nested #object #javascript
ADD COMMENT
Topic
Name
2+4 =