从对象数组中获取数值。

huangapple go评论67阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月21日 05:35:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76297448.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定