英文:
Get Values From Array of Objects
问题
请帮我处理这个问题。
我有这个对象数组:
0: {MealType: Array(4)}
1: {MealType: Array(8)}
2: {MealType: Array(8)}
3: {MealType: Array(4)}
4: {MealType: Array(4)}
5: {MealType: Array(4)}
6: {MealType: Array(4)}
我该如何使用 jQuery 获取每个MealType数组的值?
提前感谢。
我尝试了几种方法,但没有成功。
英文:
Please help me with this guys.
I have this array of objects
0: {MealType: Array(4)}
1: {MealType: Array(8)}
2: {MealType: Array(8)}
3: {MealType: Array(4)}
4: {MealType: Array(4)}
5: {MealType: Array(4)}
6: {MealType: Array(4)}
How can i Get the values of each array of MealType (with jquery)?
Thanks in advance.
I tried several things with no luck
答案1
得分: 1
以下是已翻译的内容:
const allMealTypes = recipes.flatMap(recipe => recipe.MealType);
详细信息可查看:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap
英文:
Your question doesn't specify the output's format, but for getting all meal types' values you don't need jQuery:
const allMealTypes = recipes.flatMap(recipe => recipe.MealType);
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论