I have this array of "food":
"food": [
{
"id": 11,
"name": "Kabeljaufilet",
"preis": 3.55,
"art": "mit Fisch"
},
{
"id": 12,
"name": "Spaghetti Bolognese",
"preis": 3.85,
"art": "mit Fleisch"
},
{
"id": 13,
"name": "Pizza Salami",
"preis": 3.99,
"art": "mit Fleisch"
},
Now I need another Array called "foodplan", where I can add, delete etc. foods from the first array.
I have never created Arrays where Objects of another Arrays were implemented. How to go on now?
Foodplan needs the Attributes: FoodPerWeek, where 5 food objects are in and WeekNumber Foodplan needs methods to showFood, addFood, changeFood and deleteFood.
foodplanshould just be an array, exactly like thefoodone you've got therethis.food[0]would get the first one, or you can use thefindfunction to get one, likethis.food.find((f) => f.id === 12)would return the one with id 12pushto add an item to an array.this.foodPlan.foodPerWeek.push(this.food[0])would push a copy of the first item infood, and place it infoodPerWeek