I have a Typescript object declared like this:
export class MockData {
public static food = {
"cake": {
"name": "donut",
"price": "1.5€",
"ingredients": {
"base": "biscuit",
"batter": [{
"id": "1002",
"type": "Chocolate"
},
{
"id": "1003",
"type": "Blueberry"
}
],
"toppings": [{
"id": "5002",
"type": "Glazed"
},
{
"id": "5004",
"type": "Maple"
}
]
},
"baking_time": "2h"
}
};
}
Then, from another class, I want to iterate through ingredientsproperty to access base, batter and toppings as if they were also objects (to be able to access batter elements the same way). I have tried this:
Object.keys(MockData.food.cake).forEach( element => {
console.log(element);
});
and also:
for(let prop in MockConversation.conversation.cake){
if(1){ // Test condition
console.log(prop);
}
}
But with this, I can only obtain name, price, ingredients and baking_time as strings, so I can't access their internal properties. What could I do to achieve this?