1var person ={"first_name":"Billy","last_name":"Riley"};
2var property_name="first_name";
3alert(person[property_name]); //Dynamically access object property with bracket notation
1var foo = { pName1 : 1, pName2 : [1, {foo : bar }, 3] , ...}
2
3var name = "pName"
4var num = 1;
5
6foo[name + num]; // 1
7
8// --
9
10var a = 2;
11var b = 1;
12var c = "foo";
13
14foo[name + a][b][c]; // bar
1let me = {
2 name: 'samantha',
3};
4
5// 1. Dot notation
6me.name; // samantha
7
8// 2. Bracket notation (string key)
9me['name']; // samantha
10
11// 3. Bracket notation (variable key)
12let key = 'name';
13me[key]; // samantha
14
1let nestedObject = { levelOne: { levelTwo: { levelThree : 'final destination'} } }
2
3const prop1 = 'levelOne';
4const prop2 = 'levelTwo';
5const prop3 = 'levelThree';
6
7var destination = nestedObject[prop1][prop2][prop3];
8
9// destination = 'final destination'