Question

Given the nested object below, provide the JavaScript code to navigate to the "Sugar" value (highlighted...

Given the nested object below, provide the JavaScript code to navigate to the "Sugar" value (highlighted below) and print it to the console.

var food = 
        {
                id: "0001",
                type: "donut",
                name: "Cake",
                ppu: 0.55,
                base:
                        {
                                batters:
                                        [
                                                { id: "1001", type: "Regular" },
                                                { id: "1003", type: "Blueberry" },
                                                { id: "1004", type: "Devil's Food" }
                                        ]
                        },
                topping:
                        [
                                { id: "5001", type: "None" },
                                { id: "5002", type: "Glazed" },
                                { id: "5005", type: "Sugar" },
                                { id: "5007", type: "Powdered Sugar" },
                        ]
  }

Homework Answers

Answer #1
var food =
    {
        id: "0001",
        type: "donut",
        name: "Cake",
        ppu: 0.55,
        base:
            {
                batters:
                    [
                        {id: "1001", type: "Regular"},
                        {id: "1003", type: "Blueberry"},
                        {id: "1004", type: "Devil's Food"}
                    ]
            },
        topping:
            [
                {id: "5001", type: "None"},
                {id: "5002", type: "Glazed"},
                {id: "5005", type: "Sugar"},
                {id: "5007", type: "Powdered Sugar"},
            ]
    }

console.log(food.topping[2].type);

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT