Answers for "accessing nested objects javascript"

5

accessing nested objects javascript

var ourStorage = {
  "desk": {
    "drawer": "stapler"
  },
  "cabinet": {
    "top drawer": { 
      "folder1": "a file",
      "folder2": "secrets"
    },
    "bottom drawer": "soda"
  }
};
ourStorage.cabinet["top drawer"].folder2;  // "secrets"
ourStorage.desk.drawer; // "stapler"
Posted by: Guest on July-19-2020
1

javascript nested objects

Do my eyes decieve me, or is the second answer the same as the first, but
with more upvotes?
Posted by: Guest on March-15-2021
2

how to access nested objects in javascript

var ourStorage = {
  "desk": {
    "drawer": "stapler"
  },
  "cabinet": {
    "top drawer": { 
      "folder1": "a file",
      "folder2": "secrets"
    },
    "bottom drawer": "soda"
  }
};
ourStorage.cabinet["top drawer"].folder2;  // "secrets"
ourStorage.desk.drawer; // "stapler"
Posted by: Guest on July-09-2020
0

js create nested object from fields

function assign(obj, keyPath, value) {
   lastKeyIndex = keyPath.length-1;
   for (var i = 0; i < lastKeyIndex; ++ i) {
     key = keyPath[i];
     if (!(key in obj)){
       obj[key] = {}
     }
     obj = obj[key];
   }
   obj[keyPath[lastKeyIndex]] = value;
}
Posted by: Guest on March-19-2021
0

js create nested object from fields

var settings = {};
assign(settings, ['Modules', 'Video', 'Plugin'], 'JWPlayer');
Posted by: Guest on March-19-2021

Code answers related to "accessing nested objects javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language