Preview:
// Creating a nested object
const person = {
    name: "John Doe",
    age: 30,
    address: {
        street: "123 Main St",
        city: "Anytown",
        country: "USA"
    },
    hobbies: ["reading", "traveling", "gaming"],
    contact: {
        email: "john.doe@example.com",
        phone: {
            home: "555-555-5555",
            mobile: "555-555-1234"
        }
    }
};

// Accessing properties of the nested object
console.log("Name:", person.name); // Output: "Name: John Doe"
console.log("Age:", person.age); // Output: "Age: 30"

// Accessing nested object properties
console.log("Street Address:", person.address.street); // Output: "Street Address: 123 Main St"
console.log("City:", person.address.city); // Output: "City: Anytown"
console.log("Country:", person.address.country); // Output: "Country: USA"

// Accessing hobbies
console.log("Hobbies:", person.hobbies.join(", ")); // Output: "Hobbies: reading, traveling, gaming"

// Accessing contact information
console.log("Email:", person.contact.email); // Output: "Email: john.doe@example.com"
console.log("Home Phone:", person.contact.phone.home); // Output: "Home Phone: 555-555-5555"
console.log("Mobile Phone:", person.contact.phone.mobile); // Output: "Mobile Phone: 555-555-1234"
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter