Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

access object property dynamically javascript

let nestedObject = { levelOne: { levelTwo: { levelThree : 'final destination'} } }

const prop1 = 'levelOne';
const prop2 = 'levelTwo';
const prop3 = 'levelThree';

var destination = nestedObject[prop1][prop2][prop3];

// destination = 'final destination'
 
PREVIOUS NEXT
Tagged: #access #object #property #dynamically #javascript
ADD COMMENT
Topic
Name
2+8 =