1var ourStorage = {
2 "desk": {
3 "drawer": "stapler"
4 },
5 "cabinet": {
6 "top drawer": {
7 "folder1": "a file",
8 "folder2": "secrets"
9 },
10 "bottom drawer": "soda"
11 }
12};
13ourStorage.cabinet["top drawer"].folder2; // "secrets"
14ourStorage.desk.drawer; // "stapler"
1var ourStorage = {
2 "desk": {
3 "drawer": "stapler"
4 },
5 "cabinet": {
6 "top drawer": {
7 "folder1": "a file",
8 "folder2": "secrets"
9 },
10 "bottom drawer": "soda"
11 }
12};
13ourStorage.cabinet["top drawer"].folder2; // "secrets"
14ourStorage.desk.drawer; // "stapler"
15
1function assign(obj, keyPath, value) {
2 lastKeyIndex = keyPath.length-1;
3 for (var i = 0; i < lastKeyIndex; ++ i) {
4 key = keyPath[i];
5 if (!(key in obj)){
6 obj[key] = {}
7 }
8 obj = obj[key];
9 }
10 obj[keyPath[lastKeyIndex]] = value;
11}
12
1var settings = {};
2assign(settings, ['Modules', 'Video', 'Plugin'], 'JWPlayer');
3