Question : accessing nested objects in javascript
Answered by : asif-kamal-tias
const user = { id: 101, email: '[email protected]', personalInfo: { name: 'Jack', address: { line1: 'westwish st', line2: 'washmasher', city: 'wallas', state: 'WX' } }
}
const name = user.personalInfo.name;
const userCity = user.personalInfo.address.city;
Source : https://hackernoon.com/accessing-nested-objects-in-javascript-f02f1bd6387f | Last Update : Fri, 21 Jan 22
Question : Accessing Nested Objects
Answered by : the-consciousness
The sub-properties of objects can be accessed by chaining together the dot or bracket notation.
Here is a nested object:
const ourStorage = { "desk": { "drawer": "stapler" }, "cabinet": { "top drawer": { "folder1": "a file", "folder2": "secrets" }, "bottom drawer": "soda" }
};
ourStorage.cabinet["top drawer"].folder2;
ourStorage.desk.drawer;
Source : https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects | Last Update : Sun, 21 Aug 22