-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathproblem55.js
39 lines (30 loc) · 1.07 KB
/
problem55.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* How will you access Sophia’s secondary school location? */
let data = {
Sophia: {
id: 33,
study: [
{
primary: [
{ school_name: "ABC primary school" },
{ location: "Peters burg" },
],
},
{
secondary: [
{ school_name: "ABC secondary school" },
{ location: "St Lorence" },
],
},
],
},
};
/* ==================================================
Method One: Using Dot(.) Notation
===================================================== */
const secondarySchoolLocation1 = data.Sophia.study[1].secondary[1].location;
console.log(secondarySchoolLocation1);
/* ==================================================
Method Two: Using Bracket[] Notation
===================================================== */
const secondarySchoolLocation2 = data['Sophia']['study'][1]['secondary'][1]['location'];
console.log(secondarySchoolLocation2);