I have created a constructor function that takes the input from a form to create a recipe for cooking.
function Recipe (name, method, ingredients) {
this.name = name,
this.method = method,
this.ingredients = ingredients
}
This function gets called in the POST request and pushes the output to an array called recipes
function newRecipe(name, method, ingredients) {
let r = new Recipe(name, method, ingredients)
recipeArray.push(r);
}
I want to iterate over the properties to render into EJS ie the recipe name, method and ingredients. However, i do not know how to iterate over the next index of the recipe array.
I have tried to render the properties of name, method and ingredients into a different array using a map
for (let i = 0; i < recipeArray.length; i++) {
ingredientsList = recipeArray[i].ingredients.map(ingredients => {
return ingredients;
});
}
However, I am only able to access the last index of the recipe array