Objects and Properties
Nested Objects
Read values inside an object inside another object.
Nested Objects
nested_objects.js
const city = "Austin";
const userName = ({ user: { name: "Mina", profile: { city: city } } }).user.name;
const homeCity = ({ user: { name: "Mina", profile: { city: city } } }).user.profile.city;
const badge = userName + "@" + homeCity;
console.log("user=" + userName);
console.log("city=" + homeCity);
console.log("badge=" + badge);
Walk Into the Shape
- The outer object has a
userobject. user.nameisMina.user.profile.cityisAustin.- The badge combines both values as
Mina@Austin.
user -> name -> Mina
user -> profile -> city -> Austin
nested-objects
Nested objects model structured data. Each dot moves one level deeper into the shape.
Exercise: nested_objects.js
Read a nested user name and city, then print a name-at-city badge