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" }, ] }
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);
Get Answers For Free
Most questions answered within 1 hours.