【发布时间】:2021-02-07 01:25:14
【问题描述】:
我正在使用themealdb.com API,它为您提供如下成分:
"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": "",
我正在从 API 中获取,然后使用 React Hooks 设置具有所有配方属性的对象。对于我想要这样的成分:[Quinoa, Butter, Red Chili ...].
如何遍历 JSON 并找到匹配 "strIngredient" & 而不是空字符串的键,然后将它们添加到数组中?
谢谢!
【问题讨论】:
标签: javascript html json reactjs api