I am using themealdb.com
API & it gives you the ingredients like this:
"strIngredient1": "Quinoa",
"strIngredient2": "Butter",
"strIngredient3": "Red Chilli",
"strIngredient4": "Garlic",
"strIngredient5": "Chicken Breast",
"strIngredient6": "Olive Oil",
"strIngredient7": "Black Olives",
"strIngredient8": "Red Onions",
"strIngredient9": "Feta",
"strIngredient10": "Mint",
"strIngredient11": "Lemon",
"strIngredient12": "",
"strIngredient13": "",
"strIngredient14": "",
"strIngredient15": "",
"strIngredient16": "",
"strIngredient17": "",
"strIngredient18": "",
"strIngredient19": "",
"strIngredient20": "",
I am fetching from the API & then using React Hooks to set an object with all recipe attributes. For the ingredients I want something like this: [Quinoa, Butter, Red Chili ...]
.
How do I loop through the JSON & find the keys that match "strIngredient"
& and not empty strings & then add them to an array?
Thank you!