gpt4 book ai didi

javascript - 如何组合目标数组在javascript中保存相同的键

转载 作者:行者123 更新时间:2023-12-05 02:33:42 25 4
gpt4 key购买 nike

var saperatedIngredients =  [{
ingredients: (2) ['Aar maach', 'Fish fillet']
searchfilter: "marine fish"
},
{ingredients: ['Active dry yeast']
searchfilter: "yeast"
},
{ingredients: (5) ['Ajwain', 'Cumin powder', 'Tamarind', 'Tamarind paste', 'Tamarind water']
searchfilter: "miscellaneous derived edible product of plant origin"
}
]

但我想要这样的输出

const IngredientsArray = ['Aar maach', 'Fish fillet', 'Active dry yeast','Ajwain', 'Cumin powder', 'Tamarind', 'Tamarind paste', 'Tamarind water']

有人帮我解决这个问题

最佳答案

你可以简单地使用flatMap()

var saperatedIngredients =  [{
ingredients: ['Aar maach', 'Fish fillet'],
searchfilter: "marine fish"
},
{ingredients: ['Active dry yeast'],
searchfilter: "yeast"
},
{ingredients: ['Ajwain', 'Cumin powder', 'Tamarind', 'Tamarind paste', 'Tamarind water'],
searchfilter: "miscellaneous derived edible product of plant origin"
}
]

const res = saperatedIngredients.flatMap(x => x.ingredients);

console.log(res)

关于javascript - 如何组合目标数组在javascript中保存相同的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70903947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com