I have to create and push a nested array of objects to an array.
My code snippet with an array of recipes in the file called recipes.js would look like this:
const createRecipe = () => {
const id = uuidv4()
recipes.push({
id: id,
title: '',
body: '',
ingredients: []
})
saveRecipe()
return id
}
Then, in the file ingredients.js I imported the function createRecipe() and try to push the ingredients to the recipe array like this:
const createIngredients = (recipes, text) => {
recipes.ingredients.push({
id: uuidv4(),
text,
completed: false
})
saveIngredients()
}
but my code doesn't work, I get an error
what is the right way to push this nested array of ingredients to the recipes array?